arithmetical

来源:互联网 发布:手机表白网站源码 编辑:程序博客网 时间:2024/06/05 23:01
#include<iostream.h>
#include<stdlib.h>
//定义栈内元素为字符串得堆栈Stack
struct Stack {
    char* stack;
 int  top;
 int  MaxSize;
};
//栈内的元素为字符串型的顺序栈的六种算法
void InitStack(Stack &S)
void Push(Stack &S, char item)
char Pop(Stack &S)
char Peek(Stack &S)
bool EmptyStack(Stack& S)
void ClearStack(Stack& S)
//求运算符优先级的函数
int Precedence(char op)
//将中缀表达式转换成后缀表达式的函数,其用的栈是Stack
void Change(char* S1,char* S2)
//定义栈内的元素为浮点型的堆栈Stack1
struct Stack1 {
   double* stack;
 int  top;
 int  MaxSize;
};
//栈内元素为浮点型的堆栈的六种算法
void InitStack(Stack1 &S)
void Push(Stack1 &S, double item)
double Pop(Stack1 &S)
double Peek(Stack1 &S)
bool EmptyStack(Stack1& S)
void ClearStack(Stack1& S)
//计算后缀表达式的函数,其用的堆栈为Stack1,栈内元素为double型
double Compute(char* str)
void main()
{
 char a[30];
 char b[30];
 cout<<"请输入一个中缀表达式:";
 cin.getline(a,sizeof(a));
 Change(a,b);
 cout<<"计算结果为:"<<endl;
 cout<<Compute(b)<<endl;
}
原创粉丝点击