-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.C
More file actions
69 lines (68 loc) · 915 Bytes
/
Copy pathstack.C
File metadata and controls
69 lines (68 loc) · 915 Bytes
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
#include<iostream>
using namespace std;
int top;
const int max_size=10;
int stack[max_size];
void traverse();
void push();
void pop();
int choice, item,i;
main()
{
top=-1;
cout<<"Press 1 to Push element in stack\n Press 2 to pop element from stack\n Press 3 to traverse the stack"<<endl;
cout<<"Enter your choice:";
cin>>choice;
switch(choice)
{
case 1:push();
break;
case 2:pop();
break;
case 3:traverse();
break;
}
}
void push()
{
cout<<"Enter the element you want to insert:";
cin>>item;
if(top == max_size)
{
cout<<"overflow";
}
else
{
top = top +1;
stack[top]=item;
cout<<"Element is pushed at["<<top<<"]:"<<stack[top]<<endl;
}
}
void pop()
{
if(top=-1)
{
cout<<"Underflow";
cout<<"stack is empty";
}
else
{
item=stack[top];
top=top--;
cout<<"Item is Succesfully Poped";
}
}
void traverse()
{
if(top=-1)
{
cout<<"Stack is empty";
}
else
{
for(i=0;i<top;i++)
{
cout<<"stack["<<i<<"]"<<stack[i]<<endl;
}
}
}