using namespace std;
# include "SeqStack19D Wang Yilian. H"
Template
SeqStack
{
Int top=1;
} template
SeqStack
Void SeqStack
{
If (top==StackSize - 1) throw "overflow";
Data [+ + top]=x;
}
Template
DataType SeqStack
{
DataType x;
If (top==1) throw "underflow";
X=data [top --];
return x;
}
Template
DataType SeqStack
{
If (top!=1)
The return data [top];
}
Template
Void SeqStack
{
SeqStack
char ch;
Char outch;
Cout<" Please enter the infix expression, and end with # "& lt;
while(ch!='#')
{the while (ch>='0' & amp; & Ch<='9' | | ch>='a' & amp; & Ch<='z' | | ch>='A' & amp; & Ch<='Z')//direct output Numbers and characters {cout
//meet + - if a character (ch=='+' | | ch=='-')//the lowest priority +, - {if (top==1) {C.P ush (ch);//when empty directly into the stack} else {//stack is not empty do {outch=C.P op (); If (outch=='(') {C.P ush (outch); } else {cout
//in the end, if the stack is not empty, in turn, the output stack element
While (C.t op!=1) {outch=C.P op (); Cout
} the output error, bosses to give directions
CodePudding user response:
With STD stack code changes, LZ refer to a different place yourselfusing namespace STD.
Int main () {
StackC;//here to STD stack, but does not affect the original overall train of thought
char ch;
Cout<" Please enter the infix expression, and end with # "& lt;Cin> Ch;
while(ch!='#') {
While ((ch>='0' & amp; & Ch<='9') | | (ch>='a' & amp; & Ch<='z') | | (ch>='A' & amp; & Ch<)='Z')//in digital and character directly output
{coutCh; }
//have the lowest priority +, -
If (ch=='+' | | ch=='-') {//when empty directly into the stack
while(! C.e mpty () & amp; & (C.t op ()!='(')) {//modify here
CoutC.p op ();
}
C.p ush (ch);
}
//met), output the stack elements in turn until met (and delete elements (
Else if (ch==') ') {
While (C.t op ()!='(') {
CoutC.p op ();
}
C.p op ();//here also changed the
}
Else if (ch=='(') {
C.p ush (ch);
}
//*,/, directly into the highest priority stack
Else if (ch=='*' | | ch=='/') {//here alone to separate brackets because, at the same level, but want to consider to order
//such as a/b * c suffix ab and ABC/c * */is not equivalent
///* this comment let go look at the effect
while(! C.e mpty () & amp; & (C.t op ()!='(') & amp; & (C.t op ()!='+') & amp; & (C.t op ()!='-')) {//here also changed (added at the same level of precedence)
CoutC.p op ();
}
//*/
C.p ush (ch);
}
//traversal operations meet #
Else if (ch=='#') {break; }
The else {coutCin> Ch;
}
//in the end, if the stack is not empty, in turn, the output stack element
while(! C.e mpty ()) {coutreturn 0;
}
CodePudding user response:
Please can take you to an empty function toAnd the constructor in the stack
CodePudding user response: