Data Structure Stack: Infix to Postfix
http://geeksquiz.com/stack-set-2-infix-to-postfix/
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <queue>
- #include <stack>
- #include <string>
- #include <fstream>
- #include <map>
- #include <set>
- using namespace std;
- bool isoprand(char x) {
- return x >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z';
- }
- int prec(char x) {
- if (x == '+' || x == '-') return ;
- if (x == '*' || x == '/') return ;
- if (x == '^') return ;
- return -;
- }
- int infixtopostfix(string s) {
- string ans;
- stack<char> T;
- for (int i = ; i < s.size(); i++) {
- if (isoprand(s[i])) ans += s[i];
- else if (s[i] == '(') T.push(s[i]);
- else if (s[i] == ')') {
- while (!T.empty() && T.top() != '(') {
- ans += T.top();
- T.pop();
- }
- if (!T.empty() && T.top() != '(') return -;
- T.pop();
- }
- else {
- while (!T.empty() && prec(s[i]) <= prec(T.top())) {
- ans += T.top();
- T.pop();
- }
- T.push(s[i]);
- }
- }
- while (!T.empty()) {
- ans += T.top();
- T.pop();
- }
- cout << ans << endl;
- }
- int main() {
- string s = "a+b*(c^d-e)^(f+g*h)-i";
- infixtopostfix(s);
- return ;
- }
Data Structure Stack: Infix to Postfix的更多相关文章
- uva 11995 I Can Guess the Data Structure stack,queue,priority_queue
题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...
- [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 ...
- Data Structure Stack: Reverse a stack using recursion
http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...
- HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- 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 ...
- HDU 5929 Basic Data Structure 模拟
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
UVa11995 I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...
- CDOJ 483 Data Structure Problem DFS
Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...
随机推荐
- Python--多进程--01
multiprocess import multiprocessing import time def worker_1(interval): print(' i am worker1') n=5 w ...
- R410自带SAS6IR卡折腾记
因为需要一些做一些自动编译的工作,所以打算淘换一台多核的主机.淘宝找一圈,感觉换下来的dell R410 ~ R710 都可以. 综合对比了一下感觉最低配的R410就能满足要求,最后选择了:X5675 ...
- DDD中的聚合和UML中的聚合以及组合的关系
UML:聚合关系:成员对象是整体的一部分,但是成员对象可以脱离整体对象独立存在.如汽车(Car)与引擎(Engine).轮胎(Wheel).车灯(Light)之间的关系为聚合关系,引擎.轮胎.车灯可以 ...
- spring+springMVC+hibernate整合
首先我们要知道hibernate五大对象:,本实例通过深入的使用这五大对象和spring+springMVC相互结合,体会到框架的好处,提高我们的开发效率 Hibernate有五大核心接口,分别是:S ...
- Oracle的substr函数简单用法与substring区别
substr(字符串,截取开始位置,截取长度) //返回截取的字 substr('Hello World',0,1) //返回结果为 'H' *从字符串第一个字符开始截取长度为1的字符串 subst ...
- 怎样在OpenStack上安装Ubuntu系统
转载请注明出处,否则将追究法律责任http://blog.csdn.net/xingjiarong/article/details/47011893 OpenStack是一个Iaas即基础即服务的云架 ...
- git学习之创建版本库(三)
创建版本库 什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以 ...
- 速记const 指针与指向const的指针
指向const的指针.它的意思是指针指向的内容是不能被改动的.它有两种写法. ` const int* p; (推荐) int const* p;` 再说const指针.它的意思是指针本身的值是不能被 ...
- 文件大小转换(b,kb,M,GB/TB)
//转换单位 setupSize(1111111111111); function setupSize($fileSize) { $size = sprintf("%u", $fi ...
- 转载:python基础之模块
作者:武沛齐 出处:http://www.cnblogs.com/wupeiqi/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接. 模块,用一 ...