queue container in C++
Level 4218 keystrokes
A queue is first in, first out: values are pushed at the back and popped from the front, so after one pop the front changes from 10 to 20.
C++ code
1queue<int> q;// push adds each value at the back2q.push(10);3q.push(20);4q.push(30);// front is the oldest element: prints Front: 105cout << "Front: " << q.front() << endl;// back is the newest element: prints Back: 306cout << "Back: " << q.back() << endl;// pop removes the front element (10) and returns nothing7q.pop();// Prints After pop: 208cout << "After pop: " << q.front() << endl;// Two elements are left: prints Size: 29cout << "Size: " << q.size() << endl;Output
Front: 10 Back: 30 After pop: 20 Size: 2
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 25;× 9.× 8"× 8(× 8)× 8:× 4>× 1