Miku可爱捏我是阿曼

数据结构——栈及相关操作

Human·2024-01-21 14:56·7 次阅读

数据结构——栈及相关操作

Copy
#include<bits/stdc++.h>
#define MaxSize 10
#define ElementType int
typedef struct
{
ElementType data[MaxSize];
int top;
}SqStack;
void InitStack(SqStack &S){
S.top = -1;
}
bool StackEmpty(SqStack &S){
if (S.top == -1)
{
return true;
}
return false;
}
bool Push(SqStack &S,ElementType x){
if(S.top == MaxSize - 1){
printf("Stack is full!");
return false;
}
S.top++;
S.data[S.top] = x;
return true;
}
bool Pop(SqStack &S,ElementType &x){
if(StackEmpty(S)){
return false;
}
x = S.data[S.top];
S.top--;
return true;
}
bool Get_TopElem(SqStack &S,ElementType &x){
if(StackEmpty(S)){
return false;
}
x =S.data[S.top];
return true;
}
bool print_Stack(SqStack &S){
if(StackEmpty(S)){
return false;
}else{
for(int i=S.top;i>=0;i--){
printf("%d\n",S.data[i]);
}
return true;
}
}
void test(){
SqStack S;
InitStack(S);
Push(S,1);
Push(S,2);
Push(S,3);
print_Stack(S);
}
int main()
{
test();
return 0;
}
posted @   想成为编程高手的阿曼  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示