-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_pop.cpp
71 lines (68 loc) · 1.5 KB
/
push_pop.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
#include<iostream>
using namespace std;
int const numArray=10;
int print=0;
bool push(int st[], int &size, int n );
void pop(int st[], int &size);
int main()
{
int lenArray;
int size=0;
int n;
lenArray = 10;
cout<<"Enter the number you want to push into the queue.!!";
while (size<=10){
cin >> n;
int st[numArray];
push(st, size,n);
pop(st,size);
}
return 0;
}// main.
bool push(int st[], int &size, int n){
for (int i=0; i<=size; i++){
if (i==size){
st[i]=n;
print=1;
}
if (print==1){
cout<<"Queue is :\n";
for (int i=0; i<=size; i++){
cout<<st[i]<<" ";
}
size= size++;
cout<<"\nfinish";
cout<<endl<<endl;
print =0;
return 1;
}
}//for
}// PUSH
void pop(int st[], int &size){
int popNum; int popcheck; int popVal;
if (size!=0){
cout<<"If you want to pop a value press 9 else press any other button.\n";
cin >>popNum;
if (popNum==9){
cout<< "which value do you want to be popped out\n";
cin>>popVal;
for (int i=0; i<=size; i++){
if (st[i]==popVal){
st[i]=0;
popcheck=1;
}//if.
if (popcheck==1){
for (int i=0; i<=size; i++){
cout<<st[i]<<" ";
}
size = size--;
popcheck=0;
cout<< "value popped out.\n";
}
}//for
}//if
}// if
else {
cout<<"No value to be pooped out.";
}
}