+ 6

C++ Queue Management Part 1 default code at the start

i was curious about what would happen if i just put the test case output without involving the queue class . It worked and I now want to do the test normally , so can one of you guys post the default code (the code that is already there when you click on it , not the solution)

12th May 2021, 11:45 AM
Arerea
Arerea - avatar
2 Antworten
+ 2
I'm pretty sure this was the original code: #include <iostream> using namespace std; class Queue { int size; int* queue; public: Queue() { size = 0; queue = new int[100]; } void remove() { if (size == 0) { cout << "Queue is empty"<<endl; return; } else { for (int i = 0; i < size - 1; i++) { queue[i] = queue[i + 1]; } size--; } } void print() { if (size == 0) { cout << "Queue is empty"<<endl; return; } for (int i = 0; i < size; i++) { cout<<queue[i]<<" <- "; } cout <<endl; } //your code goes here }; int main() { Queue q; q.add(42); q.add(2); q.add(8); q.add(1); q.print(); q.remove(); q.add(128); q.print(); q.remove(); q.remove(); q.print(); return 0; }
15th May 2021, 12:54 PM
Josh Greig
Josh Greig - avatar
+ 2
2nd Oct 2021, 2:23 PM
Munna Kumar