#include<stdio.h>
2 #include<stdlib.h>
3 #define TRUE 1
4 #define FALSE 0
5 //typedef struct node *pnode;
6 typedef struct node
7 {
8 int data;
9 struct node *next;
10 }Stack,*LinkStack;
11
12 int InitStack(Stack * top)
13 {
14 top->next = NULL;
15 return TRUE;
16 }
17
18 int IsEmpty(Stack * top)
19 {
20 if((top->next) == NULL)
21 return TRUE;
22 else
23 return FALSE;
24 }
25
26 int Push(Stack * top, int x)
27 {
28 Stack * p;
29 p = (Stack *)malloc(sizeof(Stack));
30 if(p == NULL)
31 return FALSE;
32 p->data = x;
33 p->next = top->next;
34 top->next = p;
35 return TRUE;
36 }
37
38 int Pop(Stack * top, int *x)
39 {
40 if(IsEmpty(top))
41 return FALSE;
42 Stack * p;
43 p = top->next;
44 *x = p->data;
45 top->next = p->next;
46 free(p);
47 }
48
49 void main()
50 {
51 int i;
52 Stack * sp;
53 sp = (Stack *)malloc(sizeof(Stack));
54 InitStack(sp);
55 for(i = 0; i <100; i++)
56 Push(sp, i);
57 int item;
58 while(!IsEmpty(sp))
59 {
60 Pop(sp, &item);
61 printf("%d ",item);
62 }
63 printf("\n");
64 }
2 #include<stdlib.h>
3 #define TRUE 1
4 #define FALSE 0
5 //typedef struct node *pnode;
6 typedef struct node
7 {
8 int data;
9 struct node *next;
10 }Stack,*LinkStack;
11
12 int InitStack(Stack * top)
13 {
14 top->next = NULL;
15 return TRUE;
16 }
17
18 int IsEmpty(Stack * top)
19 {
20 if((top->next) == NULL)
21 return TRUE;
22 else
23 return FALSE;
24 }
25
26 int Push(Stack * top, int x)
27 {
28 Stack * p;
29 p = (Stack *)malloc(sizeof(Stack));
30 if(p == NULL)
31 return FALSE;
32 p->data = x;
33 p->next = top->next;
34 top->next = p;
35 return TRUE;
36 }
37
38 int Pop(Stack * top, int *x)
39 {
40 if(IsEmpty(top))
41 return FALSE;
42 Stack * p;
43 p = top->next;
44 *x = p->data;
45 top->next = p->next;
46 free(p);
47 }
48
49 void main()
50 {
51 int i;
52 Stack * sp;
53 sp = (Stack *)malloc(sizeof(Stack));
54 InitStack(sp);
55 for(i = 0; i <100; i++)
56 Push(sp, i);
57 int item;
58 while(!IsEmpty(sp))
59 {
60 Pop(sp, &item);
61 printf("%d ",item);
62 }
63 printf("\n");
64 }