forked from omonimus1/geeks-for-geeks-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations-on-queue.cpp
More file actions
38 lines (36 loc) · 810 Bytes
/
Copy pathoperations-on-queue.cpp
File metadata and controls
38 lines (36 loc) · 810 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
// https://practice.geeksforgeeks.org/problems/operations-on-queue/1/?track=SPC-Queue&batchId=154
void enqueue(queue<int> &s,int x)
{
s.push(x);
}
// Function to remove front element from queue
void dequeue(queue<int> &s)
{
s.pop();
}
// Function to find the front element of queue
int front(queue<int> &s)
{
return s.front();
}
// Function to find the element in queue. Return "Yes" or "No".
string find(queue<int> s, int val)
{
vector<int>copy;
bool exists = false;
while(s.size())
{
if(s.front() == val)
exists = true;
copy.push_back(s.front());
s.pop();
}
// INsert again vales in queue
for(int i = 0; i < copy.size(); i++)
{
s.push(copy[i]);
}
if(exists)
return "Yes";
return "No";
}