http://geeksquiz.com/stack-set-2-infix-to-postfix/

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <stack>
  6. #include <string>
  7. #include <fstream>
  8. #include <map>
  9. #include <set>
  10. using namespace std;
  11.  
  12. bool isoprand(char x) {
  13. return x >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z';
  14. }
  15.  
  16. int prec(char x) {
  17. if (x == '+' || x == '-') return ;
  18. if (x == '*' || x == '/') return ;
  19. if (x == '^') return ;
  20. return -;
  21. }
  22.  
  23. int infixtopostfix(string s) {
  24. string ans;
  25. stack<char> T;
  26. for (int i = ; i < s.size(); i++) {
  27. if (isoprand(s[i])) ans += s[i];
  28. else if (s[i] == '(') T.push(s[i]);
  29. else if (s[i] == ')') {
  30. while (!T.empty() && T.top() != '(') {
  31. ans += T.top();
  32. T.pop();
  33. }
  34. if (!T.empty() && T.top() != '(') return -;
  35. T.pop();
  36. }
  37. else {
  38. while (!T.empty() && prec(s[i]) <= prec(T.top())) {
  39. ans += T.top();
  40. T.pop();
  41. }
  42. T.push(s[i]);
  43. }
  44. }
  45. while (!T.empty()) {
  46. ans += T.top();
  47. T.pop();
  48. }
  49. cout << ans << endl;
  50. }
  51.  
  52. int main() {
  53. string s = "a+b*(c^d-e)^(f+g*h)-i";
  54. infixtopostfix(s);
  55. return ;
  56. }

Data Structure Stack: Infix to Postfix的更多相关文章

  1. uva 11995 I Can Guess the Data Structure stack,queue,priority_queue

    题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...

  2. [Data Structure] Stack Implementation in Python

    We can realize a Stack as an adaptation of a Python List. S.push(e)=L.append(e) S.pop()=L.pop() S.to ...

  3. Data Structure Stack: Reverse a stack using recursion

    http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...

  4. HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...

  5. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  6. UVa 11995:I Can Guess the Data Structure!(数据结构练习)

    I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...

  7. HDU 5929 Basic Data Structure 模拟

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  8. 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!

    UVa11995  I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...

  9. CDOJ 483 Data Structure Problem DFS

    Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...

随机推荐

  1. Python--多进程--01

    multiprocess import multiprocessing import time def worker_1(interval): print(' i am worker1') n=5 w ...

  2. R410自带SAS6IR卡折腾记

    因为需要一些做一些自动编译的工作,所以打算淘换一台多核的主机.淘宝找一圈,感觉换下来的dell R410 ~ R710 都可以. 综合对比了一下感觉最低配的R410就能满足要求,最后选择了:X5675 ...

  3. DDD中的聚合和UML中的聚合以及组合的关系

    UML:聚合关系:成员对象是整体的一部分,但是成员对象可以脱离整体对象独立存在.如汽车(Car)与引擎(Engine).轮胎(Wheel).车灯(Light)之间的关系为聚合关系,引擎.轮胎.车灯可以 ...

  4. spring+springMVC+hibernate整合

    首先我们要知道hibernate五大对象:,本实例通过深入的使用这五大对象和spring+springMVC相互结合,体会到框架的好处,提高我们的开发效率 Hibernate有五大核心接口,分别是:S ...

  5. Oracle的substr函数简单用法与substring区别

    substr(字符串,截取开始位置,截取长度) //返回截取的字 substr('Hello World',0,1) //返回结果为 'H'  *从字符串第一个字符开始截取长度为1的字符串 subst ...

  6. 怎样在OpenStack上安装Ubuntu系统

    转载请注明出处,否则将追究法律责任http://blog.csdn.net/xingjiarong/article/details/47011893 OpenStack是一个Iaas即基础即服务的云架 ...

  7. git学习之创建版本库(三)

    创建版本库 什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以 ...

  8. 速记const 指针与指向const的指针

    指向const的指针.它的意思是指针指向的内容是不能被改动的.它有两种写法. ` const int* p; (推荐) int const* p;` 再说const指针.它的意思是指针本身的值是不能被 ...

  9. 文件大小转换(b,kb,M,GB/TB)

    //转换单位 setupSize(1111111111111); function setupSize($fileSize) { $size = sprintf("%u", $fi ...

  10. 转载:python基础之模块

    作者:武沛齐 出处:http://www.cnblogs.com/wupeiqi/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接. 模块,用一 ...