#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int val;
struct node* next;
}node;
void push(node *, int);
int pop(node *);
int main()
{
node head;
head.next=NULL;
push(&head,1);
push(&head,2);
push(&head,3);
push(&head,4);
printf("%d ",pop(&head));
printf("%d ",pop(&head));
printf("%d ",pop(&head));
printf("%d ",pop(&head));
return 0;
}
void push(node * target, int val)
{
node * newnode=(node *)malloc(sizeof(node));
node * temp=target->next;
newnode->val=val;
target->next=newnode;
newnode->next=temp;
}
int pop(node * target)
{
int res;
node * kill=(node *)malloc(sizeof(node));
if(target==NULL) abort();
else if(target->next->next!=NULL) res=pop(target->next);
else
{
res=target->next->val;
kill=target->next;
target->next=NULL;
free(kill);
}
return res;
}