栈的链式存储结构操作及实现
来源:互联网 发布:喝咖啡的利弊 知乎 编辑:程序博客网 时间:2024/04/30 14:25
栈的链式存储结构操作及实现
/*栈的链式存储结构操作及实现 */ #include<iostream>#include<cstdio>#include<cstring>#include<stdlib.h>using namespace std;typedef int SElemType; //这里用int示例typedef struct StackNode //节点的定义 {SElemType data;struct StackNode *next;}StackNode,*LinkStackPtr;typedef struct LinkStack //栈结构的定义 {LinkStackPtr top;int count;}LinkStack;int StackEmpty(LinkStack *S){if(S->top==NULL) return 1;else return 0;}void Push(LinkStack *S,SElemType e){LinkStackPtr p=(LinkStackPtr)malloc(sizeof(StackNode));p->data=e;p->next=S->top;S->top=p;S->count++;}int Pop(LinkStack *S,SElemType &e){LinkStackPtr p;if(StackEmpty(S)) return 0;e=S->top->data;p=S->top;S->top=S->top->next;free(p);S->count--;return 1;}int main(){int flag;SElemType a,b; LinkStack sta;sta.top=NULL;cout<<"请压入元素,输入0结束"<<endl;while(cin>>a&&a){Push(&sta,a);cout<<"成功压入( ⊙o ⊙)"<<endl;cout<<"现在栈顶是:";cout<<sta.top->data<<endl; } cout<<"是否弹栈?弹请选择1,否则选2结束"<<endl;cout<<"1.弹 2.不弹,结束"<<endl;while(cin>>a&&a==1){ flag=Pop(&sta,b);if(flag)cout<<"成功弹出了"<<b<<endl;else {cout<<"栈空了,再见"<<endl; break;}}return 0;}
1 0
- 栈的链式存储结构操作及实现
- 栈的链式存储结构及实现
- 栈的链式存储结构及实现
- JAVA实现队列 队列的链式存储结构及操作
- 队列的链式存储结构及实现
- 队列的链式存储结构及实现
- 栈的链式存储结构及C实现
- 栈的链式存储结构及简单实现
- Java基础 - 栈的链式存储结构及实现
- 集合的链式存储及操作实现
- 链式栈存储实现及操作
- 栈的链式存储结构与操作
- 栈的链式存储结构与操作
- 栈的链式存储结构的实现
- 栈的链式存储结构C++实现
- 线性结构--->栈的链式存储实现
- 栈的链式存储结构以及实现
- 栈的链式存储结构和实现
- 交换排序
- UVALive 4225 Prime Bases 贪心
- gmapping链接收集
- ACM程序设计题目 Problem M-13
- Sublime Text 设置
- 栈的链式存储结构操作及实现
- POJ
- [oracle]Ubuntu下ORA-27102及ORA-00845错误处理
- 实习 day5
- 剑指Offer 11 数值的整数次方
- View、自定义View
- LocakOption 参数
- L1-002. 打印沙漏
- java swing入门 计算器布局