#include <stdio.h>
#include <stdlib.h>
#define MaxSize 25
typedef struct
{
char data[MaxSize];
int top;
}SqType;
typedef struct
{
double data[MaxSize];
int top;
}SqType1;
void InitStack(SqType*& s) {
s = (SqType*)malloc(sizeof(SqType));
s->top = -1;
}
void DestroyStack(SqType*& s) {
free(s);
}
bool StackEmpty(SqType* s) {
return s->top == -1;
}
bool Push(SqType*& s, char e) {
if (s->top == MaxSize - 1) {
return false;//满
}
s->top++;
s->data[s->top] = e;
return true;
}
bool Pop(SqType*& s, char& e) {
if (s->top == -1) {
return false;//栈空
}
e = s->data[s->top];
s->top--;
return true;
}
bool GetTop(SqType* s, char& e) {
if (s->top == -1) {
return false;
}
e = s
C语言利用栈求解后缀表达式及其值
最新推荐文章于 2024-04-15 21:08:01 发布
本文介绍了如何使用C语言通过栈数据结构来解决后缀表达式(逆波兰表达式)的计算问题,详细阐述了算法流程,并提供了具体的代码实现。
摘要由CSDN通过智能技术生成