数字表达式求值程序 (c/c++)
一个控制台下的数字表达式求值程序 (c/c++)
源代码见下:
#include <stdio.h>
#include <string>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <stack>
using namespace std;
//设置运算符优先级的算法
int Priority(const string opera) // 运算符优先级
{
if(opera=="+"||opera=="-")
{
return (1);
}
else if(opera=="*"||opera=="/")
{
return (2);
}
else
{
return (0);
}
}
void MiddlefixToPostfix(vector<string> &ivec1,vector<string> &ivec2)
//中缀表达式到后缀表达式的转换算法,ivec2中存放的是中缀表达式,将其转换为后缀表达式形式存放到ivec2中。
{
//定义一个存放操作符的栈对象。
stack<string> operatorstk;
for(vector<string>::size_type i=0;i!=ivec2.size();++i)
{
if(ivec2[i]=="(")
{
operatorstk.push(ivec2[i]);
}
else if(ivec2[i]=="+"||ivec2[i]=="-"||ivec2[i]=="*"||ivec2[i]=="/")
{
if(operatorstk.empty())
{
operatorstk.push(ivec2[i]);
}
else
{
if(Priority(ivec2[i])<=Priority(operatorstk.top()))
{
while( operatorstk.empty()==false && operatorstk.top()!="(" )
{
ivec1.push_back(operatorstk.top());
operatorstk.pop();
}
operatorstk.push(ivec2[i]);
}
else
{
相关文档:
一、c++ 调C:
/* c语言头文件:cExample.h */
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
#ifdef __cplusplus
extern "C"
{
#endif
int add(int x,int y);
#ifdef __cplusplus
}
#endif
#endif
/* c语言实现文件:cExample.c */
#include "cExample.h"
int add( int x, int y )
{
return ......
c++库文件中的符号的含义:
所有的符号都是以下划线加上大写字母也就是"_Z"开头,对于在 类里或者命名空间中的符号,后面紧跟"N",然后是各个命名空间和类的名字,每个名字前是名字字符串的长度,随后是大写字母"E",对于一个函数,他的参数列表都在E后面, ......
1.c调用python:
实例代码:
main.c调用test.py的
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//main.c
#include <windows.h>
......
Objective C 2.0 简明教程 (5) 属性(Property)
作者:Administrator
周六, 2009年 03月 28日 07:47
Objective C 2.0 为我们提供了property。它大大简化了我们创建数据成员读写函数的过程,更为关键的是它提供了一种更为简洁,易于理解的方式来访问数据成员。 ......