#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int data;
struct node *next;
} node;
node *top;
void initialize ()
{
top = NULL;
}
void push(int value)
{
node *tmp;
tmp = (node *) calloc (1, sizeof(node));
tmp -> data = value;
tmp -> next = top;
top = tmp;
}
int pop (void)
{
node *tmp;
int n;
tmp = top;
n = tmp->data;
top = top->next;
free (tmp);
return (n);
}
int topvalue (void)
{
return (top->data);
}
int isempty (void)
{
return (top==NULL);
}
void display (node *head)
{
if (head == NULL)
{
printf ("NULL\n");
}
else
{
printf ("[%d] ", head -> data);
display (head->next);
}
}
int main (void)
{
initialize();
push(22);
push(33);
push(44);
printf ("The top is %d\n", topvalue());
pop();
printf("The top after pop is %d\n", topvalue());
display(top);
return (0);
}