MCPcopy Create free account
hub / github.com/Lakhankumawat/LearnCPP / dequeue

Method dequeue

Q-Queue/QueueUsingStacks.cpp:17–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 }
16
17 int dequeue(){
18 if(s1.empty() && s2.empty()){
19 cout << "Error" << endl;
20 exit(0);
21 }
22 //REVERESE STACK1 BY USING STACK2
23 if(s2.empty()){
24 while(!s1.empty()){
25 s2.push(s1.top());
26 s1.pop();
27 }
28 }
29 //THEN SIMPLY POPPING THE FIRST ELEMENT OF STACK2, i.e. THE LAST ELEMENT OF STACK1
30 int topval = s2.top();
31 s2.pop();
32
33 return topval;
34 }
35
36 // RETURNS TRUE IF BOTH STACKS ARE EMPTY
37 bool empty(){

Callers 1

mainFunction · 0.45

Calls 4

emptyMethod · 0.80
pushMethod · 0.45
topMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected