stack container in C++
Level 4214 keystrokes
A stack is last in, first out: the most recently pushed value is on top, so after one pop the top changes from 30 to 20.
C++ code
1stack<int> s;// push places each value on top of the stack2s.push(10);3s.push(20);4s.push(30);// top is the last value pushed: prints Top: 305cout << "Top: " << s.top() << endl;// pop removes the top element (30) and returns nothing6s.pop();// Prints After pop: 207cout << "After pop: " << s.top() << endl;// Two elements are left: prints Size: 28cout << "Size: " << s.size() << endl;// empty() is false, printed as 0: Empty: 09cout << "Empty: " << s.empty() << endl;Output
Top: 30 After pop: 20 Size: 2 Empty: 0
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