-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStack_Using_Array.cpp
84 lines (77 loc) · 1.47 KB
/
Stack_Using_Array.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
82
83
84
// Stack Using Array.
#include<iostream>
using namespace std;
#define SIZE 5
int A[SIZE];
int top = -1;
bool isEmpty()
{
if(top==-1)
return true;
else
return false;
}
void push(int value)
{
if(top==SIZE-1)
{
cout<< "Stack is Full!\n";
}
else
{
top++;
A[top]=value;
}
}
void pop()
{
if(isEmpty())
cout<< "Stack is Empty!\n";
else
top--;
}
void show_top()
{
if(isEmpty())
cout<< "Stack is Empty!\n";
else
cout<< "Element at Top is: " << A[top] << "\n";
}
void displayStack()
{
if(isEmpty())
{
cout<< "Stack is Empty!\n";
}
else
{
for(int i=0; i<=top; i++)
cout<< A[i] << " ";
cout<< "\n";
}
}
int main()
{
int choice, flag=1, value;
while (flag == 1)
{
cout<< "\n1.Push \n2.Pop \n3.Show Top \n4.Display Stack \n5.Exit\n";
cout<< "\nEnter Your Choice: ";
cin>> choice; switch (choice)
{
case 1: cout<< "Enter Value: ";
cin>> value;
push(value);
break;
case 2: pop();
break;
case 3: show_top();
break;
case 4: displayStack();
break;
case 5: flag = 0;
break;
}
}
return 0;
}