/* stack.c */
/* use of linear list for stack */
#include <stdio.h>
#include <stdlib.h>

struct stack {
	int d;
	struct stack *next;
};

struct stack *push(int x, struct stack *s)
{
	struct stack *new_s;

	new_s = (struct stack*)malloc(sizeof(struct stack));
	new_s->next = s;
	new_s->d    = x;
	return(new_s);
}

struct stack *pop(int *xp, struct stack *s)
{
	struct stack *next_s;

	*xp = s->d;
	next_s = s->next;
	free(s);
	return(next_s);
}

int main()
{
	struct stack *sp;
	int x,y;

	sp = push(1,NULL);
	printf("%d %d %ld\n",x,y,(long int)sp);
	sp = push(2,sp);
	printf("%d %d %ld\n",x,y,(long int)sp);
	sp = pop(&x,sp);
	printf("%d %d %ld\n",x,y,(long int)sp);
	sp = pop(&y,sp);
	printf("%d %d %ld\n",x,y,(long int)sp);
	return(0);
}

	