#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
typedef struct Stack{
int data;
struct Stack *next;
}S1,*S2;
void Print(S2 s)
{
S2 tmp = s;
while(tmp->next)
{
tmp = tmp->next;
printf("%d ",tmp->data);
}
printf("\n");
}
void Init(S2 *s,int n)
{
(*s) = (S2)malloc(sizeof (S1));
(*s)->next = NULL;
S2 tmp = (*s);
int i;
for(i = 1;i<=n;++i)
{
S2 p = (S2) malloc(sizeof (S1));
int t;
scanf("%d", &t);
p->data = t;
p->next = tmp->next;
tmp->next = p;
tmp = (*s);
}
Print(*s);
}
void pop(S2 s)
{
//printf("%d",s->data);
S2 tmp = s->next;
s->next = tmp->next;
// printf("%d\n",s->next->data);
// free(tmp);
Print(s);
}
void Push(S2 s,int e)
{
S2 tmp = (S2)malloc(sizeof (S1));
tmp->data = e;
tmp->next = s->next;
s->next = tmp;
Print(s);
}
void Getlength(S2 s)
{
S2 tmp = s;
int sum = 0;
while(tmp->next)
{
tmp = tmp->next;
sum++;
}
printf("%d\n",sum);
}
S2 s;
void solve(){
printf("1.Create a Linklist Stake\n");
printf("2.pop the top element\n");
printf("3.push the element\n");
printf("4.Getlength\n");
}
int main(){
int pos = 1;
solve();
while(pos)
{
scanf("%d", &pos);
if(pos == 1)
{
printf("1.Create a Linklist Stake\n");
printf("Please input the length\n");
int n;
scanf("%d",&n);
Init(&s,n);
}
if(pos == 2)
{
printf("2.pop the top element\n");
pop(s);
}
if(pos == 3)
{
printf("3.push the element\n");
printf("Please input your number\n");
int e;
scanf("%d", &e);
Push(s,e);
}
if(pos == 4)
{
//printf("4.Getlength\n");
Getlength(s);
}
solve();
}
return 0;
}