1#include <stdio.h>
2#include <stdlib.h>
3#define TRUE 1
4#define FALSE 0
5
6struct node
7{
8 int data;
9 struct node *next;
10};
11typedef struct node node;
12
13node *top;
14
15void initialize()
16{
17 top = NULL;
18}
19
20void push(int value)
21{
22 node *tmp;
23 tmp = malloc(sizeof(node));
24 tmp -> data = value;
25 tmp -> next = top;
26 top = tmp;
27}
28
29int pop()
30{
31 node *tmp;
32 int n;
33 tmp = top;
34 n = tmp->data;
35 top = top->next;
36 free(tmp);
37 return n;
38}
39
40int Top()
41{
42 return top->data;
43}
44
45int isempty()
46{
47 return top==NULL;
48}
49
50void display(node *head)
51{
52 if(head == NULL)
53 {
54 printf("NULL\n");
55 }
56 else
57 {
58 printf("%d\n", head -> data);
59 display(head->next);
60 }
61}
62
63int main()
64{
65 initialize();
66 push(10);
67 push(20);
68 push(30);
69 printf("The top is %d\n",Top());
70 pop();
71 printf("The top after pop is %d\n",Top());
72 display(top);
73 return 0;
74}
75