-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackMenu.c
More file actions
104 lines (82 loc) · 1.89 KB
/
StackMenu.c
File metadata and controls
104 lines (82 loc) · 1.89 KB
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
95
96
97
98
99
100
101
102
103
104
/*
This module contains all the menu driven UI for the user and the process methods for
the users input.
*/
/**
* Shows the menu options for the user to operate the stack.
*/
void ShowStackMenu(int StackArray[]){
printf("Enter the number to execute an operation: ");
PushLine();
printf("1. Push (Insert) element."), PushLine();
printf("2. Pop (Remove) element."), PushLine();
printf("3. Show elements."), PushLine();
printf("4. Quit."), PushLine();
int _userChoice;
scanf("%d", &_userChoice);
ProcessMenuChoice(StackArray, _userChoice);
}
void ProcessMenuChoice(int StackArray[], int choice){
enum e_ChoiceNames{
e_Choice_Push = 1,
e_Choice_Pop = 2,
e_Choice_Show = 3,
e_Choice_Exit = 4
};
do{
switch(choice){
case ((int)e_Choice_Push):{
if(IsStackFull()){
ClearTerminal();
printf("The stack is full and thus no more elements can be pushed into it.");
PushLine(), PushLine();
PromptToPressKey();
ClearTerminal();
}
else{
int input;
ClearTerminal();
printf("Enter the value that you want to push into the stack.");
PushLine();
scanf("%d", &input);
StackInsert(StackArray, input);
ClearTerminal();
}
ShowStackMenu(StackArray);
break;
}
case ((int)e_Choice_Pop):{
ClearTerminal();
StackRemove(StackArray);
ClearTerminal();
ShowStackMenu(StackArray);
break;
}
case (int)e_Choice_Show:{
ClearTerminal();
ArrayPrint(StackArray);
PromptToPressKey();
ClearTerminal();
ShowStackMenu(StackArray);
break;
}
case (int)e_Choice_Exit:{
ClearTerminal();
printf("Program has been terminated.");
getch();
exit(0);
break;
}
default:{
ClearTerminal();
printf("The given input is invalid.");
PushLine();
PromptToPressKey();
ClearTerminal();
ShowStackMenu(StackArray);
break;
}
}
}
while(true);
}