长沙理工大学数据结构栈的实现及应用算术表达式求值实验报告

//判断TypeStack是否为满 bool IsFull_Type(Stack S) { }

void Push_Char(Stack *S, char ch) { }

void Push_Type(Stack *S, Type a) { }

char Pop_Char(Stack *S)

//TypeStack不为满则入栈,否则输出提示 if(!IsFull_Type(*S))

S->TypeStack[S->TypeTop++] = a; //charStack不为满则入栈,否则输出提示 if(!IsFull_Char(*S))

S->charStack[S->charTop++] = ch; return S.TypeTop == MAX;

else

cout << \

else

cout << \

{ }

Type Pop_Type(Stack *S) { }

char Top_Char(Stack S) {

if(!IsEmpty_Char(S)) if(!IsEmpty_Type(*S)) { } else

cout << \S->TypeTop--;

return S->TypeStack[S->TypeTop]; if(!IsEmpty_Char(*S)) { } else

cout << \S->charTop--;

return S->charStack[S->charTop];

return -1;

return -1;

}

return S.charStack[--S.charTop];

else

cout << \

return -1;

Type Top_Type(Stack S) { }

Type Calculate(Type left, Type right, char op) {

Type value = 0; switch(op) {

case '+': value = left + right; break; case '-': value = left - right; break; case '*': value = left * right; break; case '/': if(right != 0)

value = left / right;

if(!IsEmpty_Type(S))

return S.TypeStack[--S.TypeTop];

else

cout << \

return -1;

else

}

cout << \被除数不能为零!\

break;

case '%': if(right != 0)

value = (int)left % (int)right;

else

cout << \被余数不能为零!\

break;

case '^': value = pow(left,right); /*value = 1; }

return value;

if(right >= 0)

while(right--)

value *= left;

else { }*/

right = -right; while(right--)

value /= left;

void Computer(char *mid_equotion, Type len) {

Type right, left , result;

联系客服:779662525#qq.com(#替换为@)