1.堆栈的顺序实现及后缀表达式的计算(后缀表达式只由0-9的数字和加减乘除组成)
#include <stdio.h>
#include <stdlib.h>
#define maxsize 100
typedef enum{true,false
}bool;
typedef struct SNode * Stack;
typedef int ElementType;
//定义堆栈结构
struct SNode{
ElementType data[maxsize];
int top;
};
//生成空堆栈
Stack createStack(){
Stack stack=(Stack)malloc(sizeof(struct SNode));
stack->top=0;
}
// 判断堆栈是否已满
bool isFull(Stack s){
if(s->top==maxsize){
return true;
}
return false;
}
//入栈
bool push(Stack s,ElementType e){
if(s->top==maxsize){
printf("栈满\n");
return false;
}
else{
s->data[s->top]=e;
s->top++;
return true;
}
}
//出栈
ElementType pop(Stack s){
if(s->top==0){
printf("栈空\n");
return ;
}
ElementType e=s->data[s->top-1];
s->top--;
return e;
}
//判断是否为空
bool isEmpty(Stack s){
if(s->top==0){
return true;
}
return false;
}
//读取后缀表达式并计算其结果,只能计算不带括号的0-9数字的加减乘除
ElementType compute(c