#include<stdio.h>
#include<iostream.h>
#define MAXSIZE 1024
typedef char DataType;
typedef struct
{
DataType data[MAXSIZE];
int top;
}SeqStack;
SeqStack *s;
SeqStack *Init_SeqStack()
{
SeqStack *s;
s=new SeqStack;
if(!s)
{
printf("空间不足\n");
return NULL;
}
else
{
s->top=-1;
return s;
}
}
int Enpty_SeqStack(SeqStack *s)
{
if(s->top==-1)
return 1;
else
return 0;
}
int Push_SeqStack(SeqStack *s,DataType x)
{
if(s->top==MAXSIZE-1)
return 0;
else
{
s->top++;
s->data[s->top]=x;
return 1;
}
}
int Pop_SeqStack(SeqStack *s,DataType x)
{
if(Empty_SeqStack(s))
return 0;
else
{
*x=s->data[s->top];
s->top--;
return 1;
}
}
double calcul_exp(char *A)
{
Seq_Starck s;
ch=*A++;
Init_SeqStack(s);
while(ch!='#')
{
if(ch!=运算符)
Push_SeqStack(s,ch);
else
{
Pop_SeqStack(s,&b);
Pop_SeqStack(s,&a);
switch(ch)
{
case ch=='+': c=a+b;break;
case ch=='-': c=a-b;break;
case ch=='*': c=a*b;break;
case ch=='/': c=a/b;break;
case ch=='%': c=a%b;break;
}
Push_SeqStack(s,c);
}
ch=*A++;
}
Pop_SeqStack(s,result);
return result;
}
main()
{
SeqStack s;
Init_SeqStack();
Enpty_SeqStack(s);
Push_SeqStack(s,x);
}
#include<iostream.h>
#define MAXSIZE 1024
typedef char DataType;
typedef struct
{
DataType data[MAXSIZE];
int top;
}SeqStack;
SeqStack *s;
SeqStack *Init_SeqStack()
{
SeqStack *s;
s=new SeqStack;
if(!s)
{
printf("空间不足\n");
return NULL;
}
else
{
s->top=-1;
return s;
}
}
int Enpty_SeqStack(SeqStack *s)
{
if(s->top==-1)
return 1;
else
return 0;
}
int Push_SeqStack(SeqStack *s,DataType x)
{
if(s->top==MAXSIZE-1)
return 0;
else
{
s->top++;
s->data[s->top]=x;
return 1;
}
}
int Pop_SeqStack(SeqStack *s,DataType x)
{
if(Empty_SeqStack(s))
return 0;
else
{
*x=s->data[s->top];
s->top--;
return 1;
}
}
double calcul_exp(char *A)
{
Seq_Starck s;
ch=*A++;
Init_SeqStack(s);
while(ch!='#')
{
if(ch!=运算符)
Push_SeqStack(s,ch);
else
{
Pop_SeqStack(s,&b);
Pop_SeqStack(s,&a);
switch(ch)
{
case ch=='+': c=a+b;break;
case ch=='-': c=a-b;break;
case ch=='*': c=a*b;break;
case ch=='/': c=a/b;break;
case ch=='%': c=a%b;break;
}
Push_SeqStack(s,c);
}
ch=*A++;
}
Pop_SeqStack(s,result);
return result;
}
main()
{
SeqStack s;
Init_SeqStack();
Enpty_SeqStack(s);
Push_SeqStack(s,x);
}