add new file
[mim] / src / mim / Nominee.c
1 #include "Nominee.h"
2
3 void InitNom(Nominee *N)
4 {
5         N->top = -1;
6 }
7
8 gint NomEmpty(Nominee *N)
9 {
10         return N->top == -1;
11 }
12
13 gint NomFull(Nominee *N)
14 {
15         return N->top == NomSize-1;
16 }
17
18 void push(Nominee *N,DataType d)
19 {
20         if (NomFull(N))
21         {
22                 g_printf("Nominee is full!");
23                 return ;
24         }
25         N->data[++N->top] = d;
26 }
27
28 DataType pop(Nominee *N)
29 {
30         if (NomEmpty(N))
31         {
32                  g_printf("Nominee is empty!\n");
33                  return FALSE;
34         }
35         return(N->data[N->top--]);
36 }
37
38 gint num(Nominee *N)
39 {
40         return ++N->top;
41 }
42
43 gchar* disp(Nominee *N)
44 {
45         if (NomEmpty(N))
46         {
47                 g_printf("Nomieen is empty!\n");
48                 return ;
49         }
50         gint count = N->top;
51         
52         strcpy(UD_Phrase, N->data[N->top--]);
53
54         while(N->top != -1)
55         {
56                 strcat(UD_Phrase, N->data[N->top--]);
57         }
58         g_printf("%s\n",UD_Phrase);
59
60         return UD_Phrase;
61 }
62
63 gint main()
64 {
65         Nominee *S;
66         S = (Nominee *)g_slice_alloc0(sizeof(Nominee));
67         g_printf("Initialize the stack.\n");
68         InitNom(S);
69         push(S,"aaa");
70         push(S,"bbb");
71         push(S,"ccc");
72         push(S,"ddd");
73
74         g_printf("pop a element\n");
75         DataType aa = pop(S);
76         
77         disp(S);
78         g_slice_free(Nominee, S);
79 }