MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Queue

Class Queue

GeeksForGeeks/QueueUsingStacks/solution.cpp:11–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9// 3. Push everything back to stack1.
10
11struct Queue
12{
13 stack<int> s1;
14 stack<int> s2;
15
16 // oldest entered element is always at the top of stack 1
17 void enque(int x)
18 {
19 s1.push(x);
20 }
21
22 // deQueue operation just pops from stack1
23 int dequeue()
24 {
25 if(s1.empty())
26 return 0;
27 else
28 {
29 while(!s1.empty())
30 {
31 s2.push(s1.top());
32 s1.pop();
33 }
34 }
35 int x = s2.top();
36 s2.pop();
37 return x;
38 }
39};
40
41int main()
42{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected