-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharrayStack.cpp
More file actions
79 lines (56 loc) · 1.36 KB
/
arrayStack.cpp
File metadata and controls
79 lines (56 loc) · 1.36 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
#include<bits/stdc++.h>
using namespace std;
// Stack implementation using array
int t = -1;
int* arr = (int*) malloc(sizeof(int)*1024);
void push(int val){
arr[++t] = val;
}
void pop(){
arr[t--] = 0;
}
int top(){
return arr[t];
}
int size(){
return t+1;
}
bool isEmpty(){
return t == (-1);
}
void printAll(){
for(int i = t; i >= 0; i--) cout << arr[i] << " ";
cout << endl;
}
int main(){
int cs = 0;
while(cs != 9){
int temp, cs;
cout << "Enter your choice\n1.push\n2.pop\n3.top\n4.size\n5.isEmpty\n6.printASll\n9.Exit" << endl;
cin >> cs;
switch(cs){
case 1:
cout << "enter value" << endl;
cin >> temp;
push(temp);
break;
case 2:
pop();
cout << "done" << endl;
break;
case 3:
cout << "Top value is: " << top() << endl;
break;
case 4:
cout << "Size of the stack is: " << size() << endl;
break;
case 5:
if(isEmpty()) cout << "Stack is empty" << endl;
else cout << "Stack is not empty" << endl;
break;
case 6:
printAll();
break;
}
}
}