generated from Suvechchhaa/HacktoberFest-DSA2022
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStack_Array.cpp
86 lines (83 loc) · 1.55 KB
/
Stack_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
85
86
#include<iostream>
using namespace std;
#define size 5
int ar[size];
int front=-1,rear=-1,i;
void Print()
{
if(front==-1 || rear==-1)
{
cout<<"\nList Empty";
}
else
{
cout<<"\nYour queue: ";
for(i=front;i<=rear;i++)
{
cout<<ar[i]<<" ";
}
cout<<endl;
}
}
Insert()
{
if(rear==size-1)
{
cout<<"\nList Overflow.\n";
}
else
{
if(front==-1)
{
front++;
}
cout<<"\nEnter an element: ";
rear++;
cin>>ar[rear];
cout<<"\nElement Inserted!\n";
}
}
Delete()
{
if(front==-1)
{
cout<<"\nList Empty.";
}
else
{
cout<<"\nElement "<<ar[front]<<" got deleted\n";
rear--;
if(front>rear)
{
front=-1;
rear=-1;
}
}
}
int main()
{
int ch;
while(ch!=4)
{
cout<<"-------------Choice List-------------\n";
cout<<"1. Push an element."<<endl;
cout<<"2. Pop an element."<<endl;
cout<<"3. Print the Stack."<<endl;
cout<<"4. Exit."<<endl;
cout<<"Enter your choice:\n";
cin>>ch;
switch(ch)
{
case 1: Insert();
break;
case 2: Delete();
break;
case 3: Print();
break;
case 4: break;
default: cout<<"\nWrong Choice.\n";
break;
}
}
return 1;
}