文档介绍:#include<>
#include<>
#include<>
typedef int elemtype;
typedef struct linkstack
{
elemtype dada;
struct linkstack *next;
}linkstack;
linkstack *top;
//初始化
linkstack *init()
{
linkstack *top=(linkstack*)malloc(sizeof(linkstack));
top->next=NULL;
return top;
}
//判栈空
int empty(linkstack *top)
{
if(top->next==NULL)
return 1;
else
return 0;
}
//入栈
int push(linkstack *top,elemtype x)
{
linkstack *node;
node=(linkstack*)malloc(sizeof(linkstack));
if(node==NULL)
{
printf("error!\n");
return 0;
}
else
{
node->dada=x;
node->next=top->next;
top->next=node;
return 1;
}
}
//出栈
int pop(linkstack *top,elemtype *x)
{
linkstack *node;
if(top->next==NULL)
{
printf("error!\n");
return 0;
}
else
{
node=top->next;
*x=node->dada;
top->next=node->next;
free(node);
return 1;
}
}
//取栈顶元素
int gettop(linkstack *top,elemtype *x)
{
if(top->next==NULL)
{
printf("栈空!\n");
return 0;
}
else
{
*x=top->next->dada;
return 1;
}
}
//
//主函数
void main()
{
linkstack *top;
int iget,iflag,in;
elemtype x;
top=init();
for(;;)
{
system("cls");
printf("请选择操作:\n\t\t\t\t\t1------入栈\n\t\t\t\t\t2------判栈空\n\t\t\t\t\t3------出栈\n\t\t\t\t\t4------取栈顶元素\n\t\t\t\t\t5------退出\n");
scanf("%d",&iget);
if(iget==1)
{
printf("请输入入栈数据:\n");
scanf("%d",&x);
iflag=pus