易截截图软件、单文件、免安装、纯绿色、仅160KB

数字表达式求值程序 (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编程指南

http://man.lupaworld.com/content/develop/c&c++/c/c.htm
1. 如果参数是指针,且仅作输入用,则应在类型前加const,以防止该指针在函数体内被意外修改
2. 在函数体的“入口处”,对参数的有效性进行检查
    在函数体的“出口处”,对return语句的正确性和效率进行检 ......

C陷阱:判断宏是否等于一个常数

下面这段代码有啥错误?
#if ULONG_MAX == 0xFFFFFFFF
inline unsigned long byte_swap(unsigned long x) { return __builtin_bswap32(x); }
inline long byte_swap(long x) { return __builtin_bswap32(x); }
#else
inline unsigned long byte_swap(unsigned long x) { return __builtin_bswap64(x); }
inline long ......

【linux】c++ 内存管理(二)

3. 指针与数组的比较
不同点:
      数组:要么在惊天存储区域被创建(如全局数组),要么在栈上被创建。数组名对应着(而不是指向)一块内存,其地址与容量在生命周期内保持不变,只有数组的内容可以改变。
指针:可以随时指向任意类型的内存块,它的特征是“可变”,所以我们常用 ......

C++ XML解析之TinyXML篇

 标签:XML解析 TinyXML   [推送到技术圈]
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://panpan.blog.51cto.com/489034/104961
最近使用TinyXML进行C++ XML解析,感觉使用起来比较简单,很容易上手,本文给出一个使用TinyXML进行XML解 ......

Objective C 2.0 属性(Property)

原帖一:http://blog.csdn.net/dotphoenix/archive/2009/05/20/4203075.aspx
原贴二:http://www.cocoachina.com/bbs/read.php?tid-8008.html
@property (参数) 类型 名字;
这里的参数主要分为三类:读写属性(readwrite/readonly),setter语意(assign/retain/copy)以及atomicity(nonatomic)。
assign/retain/copy ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号