shicuo4782 2017-11-10 01:55 采纳率: 0%
浏览 364

后缀式运算编译通过之后运行停止工作???

#include
#include
#include

#include

#include

#include

#include

#include

#include

#include

#include

using std::cout;
using std::cin;
using std::endl;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define true 1
#define false 0
typedef float ElemType;
struct StackNode {
ElemType dataltem;

struct StackNode *next;

};
struct Stack {
int Size;
struct StackNode *top;
};

    void InitStack( struct Stack &S);
    void DestroyStack( struct Stack &S );

    void Push(Stack &S, ElemType &newDataItem );

// void Pop( struct Stack &S );
ElemType Pop(struct Stack &S);
void Clear( struct Stack &S );
bool isEmpty( struct Stack &S );
bool isFull( struct Stack &S );
void showStructure( struct Stack &S );

void InitStack( struct Stack &S)
{
StackNode *p;
p=new StackNode;
p->next=NULL;
p->dataltem=0;
S.top=p;
S.Size=0;
}
void DestroyStack(Stack &S )
{
Clear(S);
}
void Push(Stack &S, ElemType newDataItem )
{
if(isFull(S)){cout <<"the stack is full"< StackNode *p;
p=new StackNode;
p->next=S.top;
p->dataltem=newDataItem;
S.top=p;
S.Size++;
}

ElemType Pop( struct Stack &S )
{
if(isEmpty(S)){cout <<"the stack is empty"< else
{
StackNode *p;
p=new StackNode;
p=S.top;
S.top=S.top->next;
// cout<dataltem< return p->dataltem;
}
}
void Clear( struct Stack &S )
{
StackNode *p,*q;
p=new StackNode;
q=new StackNode;
p=S.top;
while(p->next)
{
q=p->next;
free(p);
p=q;
S.top=p;
}
cout<<"the stack has been cleared"<<endl;

}
bool isEmpty(Stack &S)
{
if(S.top->next)
{
return false;
}

else return true;

}
bool isFull( struct Stack &S )
{
if(S.Size==STACK_INIT_SIZE-1)
return true;
else return false;

}
void showStructure( struct Stack &S )
{
if(isEmpty(S)){cout<<"empty stack"< StackNode *p;
p=new StackNode;
p=S.top;
while(p->next)
{
cout <dataltem<<"\t";
p=p->next;
}
cout <<endl;
}
/*void menu()
{

cout <<endl<<"        Stack"<<endl;
cout <<"===================================="<<endl;
cout <<"      +: push elem"<<endl;
cout <<"      -: pop elem "<<endl;
cout <<"      E: if the stack is empty"<<endl;
cout <<"      F: if the stack is full"<<endl;
cout <<"      O: output the stack"<<endl;
cout <<"      C: clear the stack"<<endl;
cout <<"      Q: leave the system"<<endl<<endl;
cout <<"--------------------------------------"<<endl;

}*/
int main()
{
Stack S;
InitStack(S);
while(1)
{
cout<<"Please input a postfix express: "< char *s;
cin>>s;
int l=strlen(s);
for(int i=0;i<l;i++)
{
switch (*(s+i))
{
case '+':
float q1,q2;
q1=Pop(S);
q2=Pop(S);
Push(S,q2+q1);
break;

        case '-':
                q1=Pop(S);
                q2=Pop(S);
                Push(S,q2-q1);
                break;
        case '*':
                q1=Pop(S);
                q2=Pop(S);
                Push(S,q2*q1);
                break;
        case '/':
            {
                q1=Pop(S);
                q2=Pop(S);
                Push(S,q2/q1);
                break;

            }
        default:
            Push(S,(*(s+i))-'0');
            break;

        }
    }
    showStructure(S);

    }

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥35 平滑拟合曲线该如何生成
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站