add new file
[mim] / src / mim / Nominee.c
diff --git a/src/mim/Nominee.c b/src/mim/Nominee.c
new file mode 100644 (file)
index 0000000..5fd0081
--- /dev/null
@@ -0,0 +1,79 @@
+#include "Nominee.h"
+
+void InitNom(Nominee *N)
+{
+       N->top = -1;
+}
+
+gint NomEmpty(Nominee *N)
+{
+       return N->top == -1;
+}
+
+gint NomFull(Nominee *N)
+{
+       return N->top == NomSize-1;
+}
+
+void push(Nominee *N,DataType d)
+{
+       if (NomFull(N))
+       {
+               g_printf("Nominee is full!");
+               return ;
+       }
+       N->data[++N->top] = d;
+}
+
+DataType pop(Nominee *N)
+{
+       if (NomEmpty(N))
+       {
+                g_printf("Nominee is empty!\n");
+                return FALSE;
+       }
+       return(N->data[N->top--]);
+}
+
+gint num(Nominee *N)
+{
+       return ++N->top;
+}
+
+gchar* disp(Nominee *N)
+{
+       if (NomEmpty(N))
+       {
+               g_printf("Nomieen is empty!\n");
+               return ;
+       }
+       gint count = N->top;
+       
+       strcpy(UD_Phrase, N->data[N->top--]);
+
+       while(N->top != -1)
+       {
+               strcat(UD_Phrase, N->data[N->top--]);
+       }
+       g_printf("%s\n",UD_Phrase);
+
+       return UD_Phrase;
+}
+
+gint main()
+{
+       Nominee *S;
+       S = (Nominee *)g_slice_alloc0(sizeof(Nominee));
+       g_printf("Initialize the stack.\n");
+       InitNom(S);
+       push(S,"aaa");
+       push(S,"bbb");
+       push(S,"ccc");
+       push(S,"ddd");
+
+       g_printf("pop a element\n");
+       DataType aa = pop(S);
+       
+       disp(S);
+       g_slice_free(Nominee, S);
+}
\ No newline at end of file