⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page112.cpp

📁 包含常见的数据结构的类和函数
💻 CPP
字号:
#include <ctype.h>#include <iostream.h>#include <stack.h>int isp(char ch){  switch (ch){    case '#': return 0;    case '(': return 1;    case '^': return 7;    case '*':    case '/':    case '%': return 5;    case '+':    case '-': return 3;    case ')': return 8;    }  return -1;  }int icp(char ch){  switch (ch){    case '#': return 0;    case '(': return 8;    case '^': return 6;    case '*':    case '/':    case '%': return 4;    case '+':    case '-': return 2;    case ')': return 1;    }  return -1;  }void postfix(){  Stack<char> s;  char ch,y;  s.MakeEmpty();  s.Push('#');  while(cin.get(ch),ch!='#'){    if(isdigit(ch)) cout<<ch;      else if(ch==')')	     for(y=s.Pop();y!='(';y=s.Pop()) cout<<y;	     else {	       for(y=s.Pop();isp(y)>icp(ch);y=s.Pop()) cout<<y;	       s.Push(y);	       s.Push(ch);      }    }   while(!s.IsEmpty()){     y=s.Pop();     cout<<y;      }  cout<<endl;  }void main(){  cout<<"Now,input your expression:"<<endl;  postfix();  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -