#include<stdio.h>
#include<malloc.h>
typedef struct stack{
int elem;
struct stack *next;
}*stack_1,stack_2;
stack_2 *create(); //创建并初始化
int Judge_empty(stack_1 phead);//判空
void input(stack_1 phead);//入栈
void output(stack_1 phead);//出栈
void print(stack_1 phead);//展示栈
main()
{
stack_1 phead;
phead=create();
input(phead);//头插法
print(phead);
output(phead);
print(phead);
}
stack *create()
{
stack_1 s;
s=(stack_1)malloc(sizeof(stack_2));
s->next=NULL;
}
int Judge_empty(stack_1 phead)
{
if(phead->next==NULL)
return 1;
else return 0;
}
void input(stack_1 phead)
{
stack_1 pnew;
printf("输入信息\n");
pnew=(stack_1)malloc(sizeof(stack_2));
int x;
scanf("%d",&x);
while(x!=0)
{
pnew->elem=x;
pnew->next=phead->next;
phead->next=pnew;
scanf("%d",&x);
pnew=(stack_1)malloc(sizeof(stack_2));
}
pnew->next=NULL;
}
void output(stack_1 phead)
{
stack_1 ptemp=phead->next;
printf("%d\n",ptemp->elem);
phead->next=ptemp->next;
free(ptemp);
}
void print(stack_1 phead)
{
stack_1 ptemp=phead->next;
while(ptemp)
{
printf("%d ",ptemp->elem);
ptemp=ptemp->next;
}
printf("\n");
}
//void output(stack_1 phead)
//{
// if(Judge_empty(phead))
// {
// printf("栈空\n");
// }
// stack_1 ptemp=phead->next,x;
// while(ptemp)
// {
// x=ptemp;
// ptemp=ptemp->next;
// }
// printf("%d ",x->elem);
// free(x);
//}