用到栈和队列 , 判断大小以及求值

下面代码:

#include<stdio.h>
#include<string.h>
#include <conio.h>
#include<stdlib.h>
#include <string>
#include <stack>
#include <iostream>
#include<algorithm>
using namespace std;

#define MAXN 1000
using namespace std;
stack<char> s;  //定义了一个栈, 
 char tempStr[1000];//保存后缀表达式的字符串
char *tranfExp(char* exp)
{
   

    int i=0,j=0;
    while(exp[i] !='\0')
    {
        if(exp[i]>='0' &&exp[i]<='9')  //如果是数字字符串就保存到后缀表达式字符串中
        {
            tempStr[j++] = exp[i];
        }
        else if(exp[i] == '(' )  //如果是左括号及入栈
        {
            s.push(exp[i]);
        }
        else if(exp[i] == ')' )  //如果是右括号就把接近栈顶的左括号上面所有的运算符出栈存进字符串中  左括号出栈
        {
            while(s.empty() == false)
            {
                if(s.top() == '(' )
                {
                    s.pop();
                    break;
                }
                else
                {
                   tempStr[j++] = s.top();
                   s.pop();
                }
            }
        }
        else if(exp[i] == '+' || exp[i] == '-')   //如果的事+-|操作符就把比他优先级高或者等于的所有运算符出栈进入字符串
        {
            while(s.empty() == false)
            {
                char ch = s.top();
                if(ch == '+'||ch == '-'||ch == '/'||ch == '*')
                {

                   tempStr[j++] = s.top();
                   s.pop();
                }
                else
                    break;
            }
            s.push(exp[i]);
        }
        else if(exp[i] == '*' || exp[i] == '/')  //类似于扫描到+- 只是如果栈中有=-运算符就不用出栈  因为运算符优先级比较小
        {
            while(s.empty() == false)
            {
                char ch = s.top();
                if(ch == '/' || ch=='*')
                {
                    tempStr[j++] = s.top();
                   s.pop();
                }
                else
                    break;
            }
            s.push(exp[i]);
        }
        i++;
    }
    while(s.empty() == false)   //把栈中剩余的所有运算符出栈
    {
        tempStr[j++] = s.top();
        s.pop();
    }
    tempStr[j] = 0;   //最后一个赋值为0  也就是字符串结束的标志
    return tempStr;   //返回已经得到的后缀表达式
}
int calcExp(char* exp)// 计算后缀表达式
{
   
    while( !s.empty() )
    s.pop();
    int i=0;
    while(exp[i] != '\0')
    {
        if(exp[i]>='0' && exp[i]<='9')
        {
            s.push(exp[i]-'0');
        }
        else if(exp[i] == '-')
        {
            int m = s.top();
            s.pop();
            int n = s.top();
            s.pop();
            s.push(n-m);
        }
        else if(exp[i] == '+')
        {
            int m = s.top();
            s.pop();
            int n = s.top();
            s.pop();
            s.push(n+m);
        }
        else if(exp[i] == '/')
        {
            int m = s.top();
            s.pop();
            int n = s.top();
            s.pop();
            s.push(n/m);
        }
        else if(exp[i] == '*')
        {
            int m = s.top();
            s.pop();
            int n = s.top();
            s.pop();
            s.push(n*m);
        }
        i++;
    }
  /* while(s.empty() == false)
    {
         printf("%d",s.top());
         s.pop();
    }*/
    return s.top();
}
void init()
{
	printf("\n");
	printf("\t\t\t -----         <欢迎使用表达式翻译器>       ----   \n");
	cout<<endl<<"\t\t\t\t**************************"<<endl;
	cout<<"\t\t\t\t*【1】:后缀表达式翻译及求值         *"<<endl;
	cout<<"\t\t\t\t*【2】:判断大小                     *"<<endl;
	cout<<"\t\t\t\t*************************************"<<endl;
	cout<<"请输入选项:"; 
 } 
int main()
{
	int num1 , com[2]; 
   char str[1000] , str1[1000] ,ch[2];
   char* tranStr;
   char* tranStr1;
   tranStr = (char *)malloc(100*sizeof(char));
   tranStr1 = (char *)malloc(100*sizeof(char));
   init();
   
   while(cin >> num1)
   {
	   	if(num1 == 1)
	   {
		   printf("请输入表达式:\n");
		   scanf("%s",str);
		   tranStr =  tranfExp(str);//中缀表达式转换为后缀表达式函数
		   printf("后缀表达式:\n"); 
		   puts(tranStr); //输出转换后的后缀表达式
		   printf("表达式求值答案:\n"); 
		   printf("%d",calcExp(tranStr));
	   }
	   if(num1 == 2)
	   {
		   	printf("请输入表达式:\n");
		  	scanf("%s" , str1);
		  	tranStr =  tranfExp(str1);
		  	com[0] = calcExp(tranStr);//记录值 
		  	scanf("%s" , ch);
		  	if(ch[0] == '>')
		  	{
		  		scanf("%s" , str1);
		  		tranStr1 =  tranfExp(str1);
		  		com[1] =  calcExp(tranStr1);
		  		printf("结果:\n");
			  	if(com[0] < com[1])
				{
					printf("0\n" );
				}
				else
				{
					printf("1\n");
				}
			}
	   }
	   printf("\n按任意键继续。。。。。。");
	   getch();
	   system("cls");
	   init();
	   
   }
  
   return 0;
}