TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
queue_using_two_stacks.cpp File Reference
#include <cassert>
#include <iostream>
#include <stack>
Include dependency graph for queue_using_two_stacks.cpp:

Go to the source code of this file.

Functions

void queue_test ()
 
int main ()
 

Detailed Description

Author
shoniavika

Implementation of a Queue using two Stacks.

Definition in file queue_using_two_stacks.cpp.

Function Documentation

◆ main()

int main ( void )

Main function, calls testing function

Definition at line 141 of file queue_using_two_stacks.cpp.

141 {
142 queue_test();
143 return 0;
144}
void queue_test()

◆ queue_test()

void queue_test ( )

Testing function

Definition at line 101 of file queue_using_two_stacks.cpp.

101 {
102 MyQueue<int> que;
103 std::cout << "Test #1\n";
104 que.push(2);
105 que.push(5);
106 que.push(0);
107 assert(que.peek() == 2);
108 assert(que.pop() == 2);
109 assert(que.peek() == 5);
110 assert(que.pop() == 5);
111 assert(que.peek() == 0);
112 assert(que.pop() == 0);
113 assert(que.empty() == true);
114 std::cout << "PASSED\n";
115
116 std::cout << "Test #2\n";
117 que.push(-1);
118 assert(que.empty() == false);
119 assert(que.peek() == -1);
120 assert(que.pop() == -1);
121 std::cout << "PASSED\n";
122
123 MyQueue<double> que2;
124 std::cout << "Test #3\n";
125 que2.push(2.31223);
126 que2.push(3.1415926);
127 que2.push(2.92);
128
129 assert(que2.peek() == 2.31223);
130 assert(que2.pop() == 2.31223);
131 assert(que2.peek() == 3.1415926);
132 assert(que2.pop() == 3.1415926);
133 assert(que2.peek() == 2.92);
134 assert(que2.pop() == 2.92);
135 std::cout << "PASSED\n";
136}