forked from anshulg954/DSA-CCET
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstackpractical6.cpp
More file actions
127 lines (124 loc) · 1.75 KB
/
Copy pathstackpractical6.cpp
File metadata and controls
127 lines (124 loc) · 1.75 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include<iostream>
using namespace std;
int count=0,top=-1,top1=-1,temp;
int arr[10],arr1[10];
push()
{
if(count>10)
{
cout<<"\n Stack is Full\n";
}
else
{
cout<<"\n Enter element\n ";
top++;
cin>>arr[top];
count++;
}
}
pop()
{
if(count==0)
{
cout<<"\n Stack is already empty\n ";
}
else
{
count--;
top--;
}
}
peek()
{
int m;
cout<<"\n enter the location of element\n ";
cin>>m;
int i=top;
if(m>0 && m<=count)
{
while(i>=m)
{
temp=arr[top];
top--;
i--;
top1++;
arr1[top1]=temp;
}
temp=arr[top];
cout<<"\n Element at "<<m<<"th location is "<<temp<<endl;
i=-1;
while(top1>i)
{
temp=arr1[top1];
top1--;
top++;
arr[top]=temp;
}
}
else{
cout<<"\n Wrong location entered \n";
}
}
update()
{
int m;
cout<<"\n enter the location of element\n ";
cin>>m;
int i=top;
if(m>0 && m<=count)
{
while(i>=m)
{
temp=arr[top];
top--;
i--;
top1++;
arr1[top1]=temp;
}
cout<<"\n Enter the new value\n ";
cin>>temp;
arr[top]=temp;
i=-1;
while(top1>i)
{
temp=arr1[top1];
top1--;
top++;
arr[top]=temp;
}
cout<<"\n Updated sucessfully\n ";
}
else{
cout<<"\n Wrong location entered \n";
}
}
int main()
{
int a;
while(true)
{
cout<<" Enter your choice\n 1.Push an element\n 2.Pop an element\n 3.Peek operation\n 4.Update an element\n 5.Exit\n ";
cin>>a;
switch(a)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peek();
break;
case 4:
update();
break;
case 5:
exit(22);
break;
default:
cout<<"\n Enter Valid Choice\n ";
break;
}
}
}