This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
81 lines (70 loc) · 1.37 KB
/
main.cpp
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
// main.cpp
// Stack
//
// Created by Ömer Faruk Görmel on 30/09/14.
//
#include <iostream>
using namespace std;
int stack[5]; // Create stack
int top, maxLength;
bool full () {
if (top == maxLength) {
// Full
return false;
}
else {
return true;
}
}
bool empty () {
if (top == 0) {
// Empty
return false;
}
else {
return true;
}
}
void push () {
if (full()) {
cout << "Value : ";
cin >> stack[top];
top++;
}
else {
cout << "Full...\n";
}
}
void pop () {
if (empty()) {
top--;
stack[top] = 0; // NULL
}
else {
cout << "Empty...\n";
}
}
int main(int argc, const char * argv[]) {
top = 0, maxLength = 5; // First Value
int select;
while (select != 4) {
cout << "(1) Push\n(2) Pop\n(3) Show stack\n(4) Exit"; // Menu
cout << "\nSelect : ";
cin >> select;
switch (select) {
case 1: // Push
push();
break;
case 2: // Pop
pop();
break;
case 3: // Show stack
for (int i = 0; i<maxLength; i++) {
cout << "stack[" << i << "] : " << stack[i] << endl;
}
break;
default: cout << "Try again...\n";
}
}
return 0;
}