-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack using push n pop.cpp
More file actions
96 lines (81 loc) · 1.41 KB
/
Copy pathstack using push n pop.cpp
File metadata and controls
96 lines (81 loc) · 1.41 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
#include<iostream>
using namespace std;
#define max 10 //Maximum Size of Stack
int stack[max];
int top=-1,item; //top=-1 means Stack is Empty.
//First Element will be stored at Zero Location. (top=0)
int main()
{
int choice;
int Push();
int Pop();
int Display();
for(;;) //Infinite Loop.
{
cout<<"\n\n\n\n---------- STACK ---------- \n";
cout<<"\nMain Menu\n\n1. PUSH\n2. POP\n3. Display\n4. Exit\n\nEnter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
Push();
break;
case 2:
Pop();
break;
case 3:
Display();
break;
default:
cout<<"\nWrong Input";
return 0;
}
}
}
int Display() //Display's the Element of Stack.
{
int i;
if(top==-1)
{
cout<<"\nStack is Empty.\n";
}
else
{
for(i=top;i>=0;i--)
{
cout<<endl<<"Stack["<<i<<"]="<<stack[i];
if(i==top)
cout<<" <-- Top";
}
}
}
int Push() //Insert a New Element in Stack.
{
if(top==max-1)
{
cout<<"\nOverflow\n";
}
else
{
cout<<"\nEnter the Element you want to Insert : ";
cin>>item;
top=top+1;
stack[top]=item;
cout<<endl<<item<<" is Inserted at Top.\n";
Display();
}
}
int Pop() //Delete Element from Stack.
{
if(top==-1)
{
cout<<"\nUnderflow\n";
}
else
{
item=stack[top];
top=top-1;
cout<<endl<<item<<" is Deleted from Top.\n";
Display();
}
}