我想计算3+6的和 怎么结果是105呢?#include <iostream.h>
#define MAX 100
typedef struct
{
int data[MAX];
int top;
}SeqStack;
SeqStack *Init_SeqStack()
{
SeqStack *s;
s=new SeqStack;
if (!s)
{
return NULL;
}
else
{
s->top=-1;
return s;
}
}
int Empty(SeqStack *s){
if (s->top==-1)
return 1;
else
return 0;
}
int Push_SeqStack(SeqStack *s,int x){
if (s->top==MAX-1)
return 0;
else
{ s->top++;
s->data[s->top]=x;
return 1;
}
}
int Pop_SeqStack(SeqStack *s,int *x){
if (Empty(s))
return 0;
else
{ *x=s->data[s->top];
s->top--;
return 1;
}
}
int GetTop(SeqStack *s)
{
return(s->data[s->top]);
}
/*****/
double calcul_exp(char *A)
{
SeqStack *s;
char ch ;
s = Init_SeqStack();
int a = 0,b = 0,c = 0;
while(ch != '#')
{
if(ch != '+' && ch != '-' &&ch != '*' &&ch != '/' )
Push_SeqStack(s,ch);
else
{
Pop_SeqStack(s,&b);
Pop_SeqStack(s,&a);
switch(ch)
{
case '+': c = a + b;break;
case '-': c = a - b;break;
case '*': c = a * b;break;
case '/': c = a / b;break;
}
Push_SeqStack(s,c);
}
ch = *A++;
}
Pop_SeqStack(s,&c);
return c;
}
void main()
{
char a[10] = "36+#";
double mn = calcul_exp(a);
cout << mn;
}
|