数据结构2链栈
来源:互联网 发布:独立之空淘宝 编辑:程序博客网 时间:2024/05/21 17:15
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#define MAX 100
struct node{
int data;
struct *next;
}s;
//初始化
int InitStack(&s){
s=(node *)malloc(sizeof(node));
if(NULL==s)
return -1;
s->next=NULL;
}
//判空
int StackEmpty(&s){
if(NULL==s->next)
return 1;
return 0;
}
//求长度
int StackLength(&s){
int count=0;
node *p=s;
while(NULL!=p->next){
p=p->next;
count++;
}
return count;
}
//访问栈顶
int GetTop(&s,int *e){
if(StackEmpty(*s))
return -1;
*e=s->next->data;
return 0;
}
//入栈
int Push(&s,int e){
node *p;
p=(node *)malloc(sizeof(node));
if(p==NULL)
return -1;
p->data=e;
p->next=s->next;
s->next=p;
return 0;
}
//出栈
int Pop(&s,int *e){
node *p=NULL;
if(StackEmpty(*s))
return -1;
p=s->next;
*e=p->data;
s->next=p->next;
free(p);
return 0;
}
//主函数
int main(){
//此处并未测试
}
#include<conio.h>
#include<malloc.h>
#define MAX 100
struct node{
int data;
struct *next;
}s;
//初始化
int InitStack(&s){
s=(node *)malloc(sizeof(node));
if(NULL==s)
return -1;
s->next=NULL;
}
//判空
int StackEmpty(&s){
if(NULL==s->next)
return 1;
return 0;
}
//求长度
int StackLength(&s){
int count=0;
node *p=s;
while(NULL!=p->next){
p=p->next;
count++;
}
return count;
}
//访问栈顶
int GetTop(&s,int *e){
if(StackEmpty(*s))
return -1;
*e=s->next->data;
return 0;
}
//入栈
int Push(&s,int e){
node *p;
p=(node *)malloc(sizeof(node));
if(p==NULL)
return -1;
p->data=e;
p->next=s->next;
s->next=p;
return 0;
}
//出栈
int Pop(&s,int *e){
node *p=NULL;
if(StackEmpty(*s))
return -1;
p=s->next;
*e=p->data;
s->next=p->next;
free(p);
return 0;
}
//主函数
int main(){
//此处并未测试
}
0 0
- 数据结构2链栈
- 数据结构-链栈
- 【数据结构】链栈
- 《数据结构》链栈
- 数据结构-链栈
- 数据结构--链栈
- 数据结构-链栈
- 数据结构--链栈
- 数据结构2
- 数据结构2
- 数据结构-2
- 数据结构2
- 数据结构-2
- 数据结构2
- 数据结构2
- 数据结构2
- 数据结构(2)——大话数据结构
- 【数据结构】链栈_LinkStack
- 使用ChemDraw如何绘制箭头
- __VA_ARGS__和#、##
- 启动eclipse时报fail to create java virtual machine错误的解决办法
- 水晶报表的分栏显示
- [疯狂Java]SQL:对查询结果进行集合运算
- 数据结构2链栈
- 支付宝
- PS快捷方式
- [LintCode] 最小差 The Smallest Difference
- 如何用ChemBioDraw标记被选结构原子
- 数据结构4双向链表
- Array和Arrays,Collection和Collections的区别
- emWin界面库注意事项之自定义回调函数之后,句柄为0
- MyBatis中$和#的区别及如何应用