数字表达式求值程序 (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++ development with the Eclipse Platform
Pawel Leszek
摘要:通过本文你将获得如何在Eclipse平台上开发C/C++项目的总体认识。虽然Eclipse主要被用来开发Java项目,但它的框架使得它很容易实现对其他开发语言的支持。在这篇文章里,你将学会如何使用CDT(C/C++ Development Toolkit),一个在Eclipse平台上最 ......
3. 指针与数组的比较
不同点:
数组:要么在惊天存储区域被创建(如全局数组),要么在栈上被创建。数组名对应着(而不是指向)一块内存,其地址与容量在生命周期内保持不变,只有数组的内容可以改变。
指针:可以随时指向任意类型的内存块,它的特征是“可变”,所以我们常用 ......
Windows C 程序设计入门与提高
http://download.chinaitlab.com/program/files/13246.html
单片机C语言入门
http://download.chinaitlab.com/program/files/12907.html
C++ 入门基础教程
http://download.chinaitlab.com/program/files/7617.html
C语言常用算法源代码
http://download.chinaitlab.com/program/files ......