Home > Software engineering >  Want god to help take a look at why I here can't expand to the negative, and this why can'
Want god to help take a look at why I here can't expand to the negative, and this why can'

Time:11-19

#include
using namespace std;
#include
#include
# define MaxSize 100
Typedef char ElemType;
Typedef double ElemType1;
Typedef struct
{
ElemType data [MaxSize];//the data in the storage stack element
int top;//stack pointer, namely the storage stack elements in the data array subscript
} SqStack;//order stack type
Void InitStack (SqStack * & amp; S)//initialization function of stack
{
S=(SqStack *) malloc (sizeof (SqStack));//allocate a sequential stack space, the first address in s
S - & gt; Top=1;//the stack pointer is set to 1, said the stack is empty
}
Void DestroyStack (SqStack * & amp; S)//destroy the function of a stack
{
Free (s);
}
Bool StackEmpty (SqStack * s)//whether the stack is empty, this function is actually used to determine the s - & gt; Whether a top==1
{
The return (s - & gt; Top==1);
}
Bool Push (SqStack * & amp; S, ElemType e)//into the stack
{
If (s - & gt; Top==MaxSize - 1)//stack full, namely on the stack overflow
return false;
S - & gt; Top++;//the stack pointer to add 1
S - & gt; Data [s - & gt; top]=e;//e element in the stack pointer
return true;
}
Bool Pop (SqStack * & amp; S, ElemType & amp; E)//a stack
{
If (s - & gt; Top==1)//the stack is empty, the stack underflow
return false;
E=s - & gt; Data [s - & gt; top];//take the top element
S - & gt; Top -;//stack pointer minus 1
return true;
}
Bool GetTop (SqStack * s, ElemType & amp; E)//take the top element
{
If (s - & gt; Top==1)//the stack is empty, the stack underflow
return false;
E=s - & gt; Data [s - & gt; top];//take the top element
return true;
}
Typedef struct
{
ElemType1 data [MaxSize];//the data in the storage stack element
int top;//stack pointer, namely the storage stack elements in the data array subscript
} SqStack1;//order stack type
Void InitStack (SqStack1 * & amp; S)//initialization function of stack
{
S=(SqStack1 *) malloc (sizeof (SqStack1));//allocate a sequential stack space, the first address in s
S - & gt; Top=1;//the stack pointer is set to 1, said the stack is empty
}
Void DestroyStack1 (SqStack1 * & amp; S)//destroy the function of a stack
{
Free (s);
}
Bool StackEmpty (SqStack1 * s)//whether the stack is empty, this function is actually used to determine the s - & gt; Whether a top==1
{
The return (s - & gt; Top==1);
}
Bool Push1 (SqStack1 * & amp; S, ElemType1 e)//into the stack
{
If (s - & gt; Top==MaxSize - 1)//stack full, namely on the stack overflow
return false;
S - & gt; Top++;//the stack pointer to add 1
S - & gt; Data [s - & gt; top]=e;//e element in the stack pointer
return true;
}
Bool Pop1 (SqStack1 * & amp; S, ElemType1 & amp; E)//a stack
{
If (s - & gt; Top==1)//the stack is empty, the stack underflow
return false;
E=s - & gt; Data [s - & gt; top];//take the top element
S - & gt; Top -;//stack pointer minus 1
return true;
}
Bool GetTop1 (SqStack1 * s, ElemType1 & amp; E)//take the top element
{
If (s - & gt; Top==1)//the stack is empty, the stack underflow
return false;
E=s - & gt; Data [s - & gt; top];//take the top element
return true;
}
Void trans (char * exp, char postexp [])//exp arithmetic expression into postfix expression postexp
{
Char e;
int i=0;
SqStack * Optr;//define operators stack pointer
InitStack (Optr);//initialization operator stack
While (* exp!='\ 0')//exp expression did not scan cycle
{
The switch (* exp)
{
Case '(' ://decision left parenthesis
* exp++;
If (* exp=='-')
{
* exp='@'.
Exp -;
Push (Optr, '(');
* exp++;
break;
}
The else
{
* exp -;
Push (Optr, '(');//left parenthesis in stack
Exp++;//continue to scan the other characters
break;
}
Case ') ://decision right parenthesis
Pop (Optr, e);//the stack elements e
While (e!='(')//no (when the loop
{
Postexp [i++]=e;//will e store to postexe
Pop (Optr, e);//the stack elements e
}
Exp++;//continue to scan the other characters
break;
Case '+' ://as + or -
In case the '-' :
while(! StackEmpty (Optr))//stack is not empty cycle
{
GetTop (Optr, e);//get the stack elements e
If (e!='(')//e is not a' ('
{
Postexp [i++]=e;//will e store to postexp
Pop (Optr, e);//the stack elements e
}
The else
break;//e is a '(' exit the loop
}
Push (Optr, * exp);//the '+' or '-' into the stack
Exp++;//continue to scan the other characters
break;
Case '*' ://as a '*' or '/'
no.Case '/' :
while(! StackEmpty (Optr))//stack is not empty cycle
{
GetTop (Optr, e);//get the stack elements e
If (e=='*' | | e=='/')//e is a '*' or '/'
{
Postexp [i++]=e;//will e store to postexp
Pop (Optr, e);//the stack elements e
}
The else
break;//e is a '*' or '/' exit loop
}
Push (Optr, * exp);//the '*' or '/' into the stack
Exp++;//continue to scan the other characters
break;
Case '^' ://to # ^
while(! StackEmpty (Optr))//stack is not empty cycle
{
GetTop (Optr, e);//get the stack elements e
If (e=='^')//e is a '^'
{
Postexp [i++]=e;//will e store to postexp
Pop (Optr, e);//the stack elements e
}
The else
break;//e is a '^' exit loop
}
Push (Optr, * exp);//'^' into the stack
Exp++;//continue to scan the other characters
break;
Case 'l' ://to the log number
while(! StackEmpty (Optr))//stack is not empty cycle
{
GetTop (Optr, e);//get the stack elements e
If (e=='l')//e 'l'
{
Postexp [i++]=e;//will e store to postexp
Pop (Optr, e);//the stack elements e
}
The else
break;//e is' l 'exit the loop
}
Push (Optr, * exp);//will be 'l' into the stack
Exp +=3;//continue to scan the other characters
break;
Case 'c://to cos,
while(! StackEmpty (Optr))//stack is not empty cycle
{
GetTop (Optr, e);//get the stack elements e
If (e=='c')//e 'l'
{
Postexp [i++]=e;//will e store to postexp
Pop (Optr, e);//the stack elements e
}
The else
break;//e is a 'c' exit loop
}
Push (Optr, * exp);//'c' into the stack
Exp +=3;//continue to scan the other characters
break;
Case 's' ://judgment for sin number
while(! StackEmpty (Optr))//stack is not empty cycle
{
GetTop (Optr, e);//get the stack elements e
If (e=='s')//e is' s'
{
Postexp [i++]=e;//will e store to postexp
Pop (Optr, e);//the stack elements e
}
The else
break;//e is' s' exit the loop
}
Push (Optr, * exp);//will be 's' into the stack
Exp +=3;//continue to scan the other characters
break;
Case the 't' ://to tan,
while(! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related