Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1501213
  • 博文数量: 329
  • 博客积分: 2773
  • 博客等级: 少校
  • 技术积分: 4219
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:17
个人简介

淡定从容,宁静致远

文章分类

全部博文(329)

文章存档

2016年(4)

2015年(50)

2014年(68)

2013年(45)

2012年(162)

分类: LINUX

2014-09-09 09:53:04

#include
#include
typedef struct node
{
int data;
struct node *next;


}StackNode;
//置空栈
StackNode* Init_LinkStack(StackNode *top)
{
top=NULL;
return top;
}
//判空栈
int Empty_LinkStack(StackNode
*top)
{
if(top==NULL)
{
return 1;

}
else
{
return 0;
}


}
//入栈
StackNode* Push_LinkStack(StackNode *top,int x)
{
StackNode *s;
s=malloc(sizeof(StackNode));
s->data=x;
s->next=top;
top=s;
return top;


}
StackNode* Pop_LinkStack(StackNode *top,int *x)
{
StackNode *p;
if(top==NULL)
{
return NULL;
}
else
{
*x=top->data;
p=top;
top=top->next;
free(p);
return top;
}
}
int main()
{
StackNode top,*ls=&top,*p;
int select;
int y,z;
ls=Init_LinkStack(ls);
printf("\n(1)入栈");


printf("\n(2)出栈");
printf("\n(3)退出");


printf("\n请输入1-3\n");
scanf("%d",&select);
do
{
switch(select)
{
case 1:
printf("\n请输入入栈数据");
scanf("%d",&y);
ls=Push_LinkStack(ls,y);

printf("\n入栈结果");
p=ls;
while(p!=NULL)
{
printf("\n%d",p->data);
p=p->next;

}
break;
case 2:
ls=Pop_LinkStack(ls,&z);


printf("\n出栈结果");


p=ls;
while(p!=NULL)
{
printf("\n%d",p->data);
p=p->next;

}
break;
}

printf("\n(1)入栈");


printf("\n(2)出栈");
printf("\n(3)退出");


printf("\n请输入1-3\n");
scanf("%d",&select);
printf("\n");
}while(select!=3);
return 0;
}

阅读(766) | 评论(0) | 转发(0) |
0

上一篇:双向不循环链表

下一篇:strcat函数C实现

给主人留下些什么吧!~~