-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestStack.c
94 lines (86 loc) · 2.53 KB
/
TestStack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// filename TestStack.c
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "StackADT.h"
void TraverseStack(StackPointer Stack);
void menu(int *choice);
main()
{
StackPointer AStack;
int choice;
char ch;
StackElementType AnItem;
do
{
menu(&choice);
switch(choice)
{
case 1: CreateStack(&AStack);
break;
case 2: if (EmptyStack(AStack))
printf("Empty Stack\n");
else
while (!EmptyStack(AStack))
{
Pop(&AStack, &AnItem);
printf("KORYFAIO STOIXEIO %d\n",AnItem);
}
break;
case 3: if (EmptyStack(AStack))
printf("Empty Stack\n");
else printf("Not an Empty Stack\n");
break;
case 4: if (EmptyStack(AStack))
printf("Empty Stack\n");
else {
Pop(&AStack, &AnItem);
printf("\nKORYFAIO STOIXEIO %d\n",AnItem);
}
break;
case 5: printf("DWSE STOIXEIO GIA W8HSH: ");
scanf("%d",&AnItem);
Push(&AStack,AnItem);
break;
case 6: if (EmptyStack(AStack))
printf("Empty Stack\n");
else TraverseStack(AStack);
break;
}
} while (choice!=7);
return 0;
}
void menu(int *choice)
{
printf(" MENOY \n");
printf("-------------------------------------------------\n");
printf("1 ---- DHMIOYRGIA STOIBAS\n");
printf("2 ---- ADEIASMA THS STOIBAS\n");
printf("3 ---- ELEGXOS KENHS STOIBAS\n");
printf("4 --- POP STOIXEIOY APO TH KORYFH THS STOIBA\n");
printf("5 --- PUSH STH KORYFH THS STOIBAS\n");
printf("6 ---- EMFANISH STOIXEIWN STOIBAS (BOH8HTHKH)\n");
printf("7 ---- EXIT\n");
printf("\nChoice: ");
do
{
scanf("%d", choice);
} while (*choice<1 && *choice>7);
}
void TraverseStack(StackPointer Stack)
{
StackPointer CurrPtr;
if (EmptyStack(Stack))
{
printf("EMPTY Stack\n");
}
else
{
CurrPtr = Stack;
while ( CurrPtr!=NULL )
{
printf("%d\n", CurrPtr->Data);
CurrPtr = CurrPtr->Next;
}
}
}