August 2012
Intermediate to advanced
976 pages
30h 17m
English
The stack type is defined in the stack header. The operations provided by a stack are listed in Table 9.18. The following program illustrates the use of stack:
stack<int> intStack; // empty stack// fill up the stackfor (size_t ix = 0; ix != 10; ++ix) intStack.push(ix); // intStackholds 0 ... 9 inclusivewhile (!intStack.empty()) { // while there are still values in intStack int value = intStack.top(); // code that uses value intStack.pop(); // pop the top element, and repeat}
Table 9.18. Stack Operations in Addition to Those in Table 9.17
The declaration
stack<int> intStack; // empty stack
defines intStack to be ...
Read now
Unlock full access