-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
80 lines (74 loc) · 1.32 KB
/
Stack.cpp
File metadata and controls
80 lines (74 loc) · 1.32 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
#include<iostream>
using namespace std;
int top=-1,size;
int isFull()
{
if(top==size-1)
return 1;
else
return 0;
}
int isEmpty()
{
if(top==-1)
return 1;
else
return 0;
}
void push(int value,int stack[])
{
if(isFull())
cout<<"The stack is Full.\n";
else
stack[++top]=value;
}
void pop(int stack[])
{
if(isEmpty())
cout<<"Stack is Empty.\n";
else
cout<<stack[top--]<< " is deleted from the stack.\n";
}
void traversal(int stack[])
{
if(isEmpty())
cout<<"stack is empty\n";
else
{
cout<< "Stack: ";
int i=top;
while(i>=0)
{
cout<<"\t" <<stack[i];
i--;
}
cout<<endl;
}
}
main()
{
cout<<"Enter size of Stack.\n";
cin>>size;
int stack[size];
int choice,value;
char c;
do
{
cout<<"Enter your choice:"<<"\n1. Insertion 2. Deletion 3. Display\n";
cin>>choice;
switch(choice)
{
case 1: cout<<"Enter element to be inserted : ";
cin>>value;
push(value,stack);
break;
case 2: pop(stack);
case 3: traversal(stack);
break;
default: cout<<"Sorry wrong Input\n";
}
cout<<"enter y or Y to continue.... ";
cin>>c;
}while(c=='y'||c=='Y');
return 0;
}