c++重要指令 -- std::stake 的使用方法
std::stake 的使用方法
1. stake 特性: last-in first-out
2.重要的Member functions :
empty: Test whether container is empty
size: Return size
top: Access next element
push: Insert element
pop: Remove top element
emplace(c++11): Construct and insert element
swap(c++11): Swap contents
empty: Test whether container is empty
size: Return size
top: Access next element
push: Insert element
pop: Remove top element
emplace(c++11): Construct and insert element
swap(c++11): Swap contents
3. 使用Example:
#include <iostream> // std::cout #include <stack> // std::stack int main () { std::stack<int> myints;//宣告 std::cout << "0. size: " << myints.size() << '\n'; //Return size for (int i=0; i<5; i++) myints.push(i); // Insert element std::cout << "1. size: " << myints.size() << '\n'; myints.pop(); //Remove top element std::cout << "2. size: " << myints.size() << '\n'; return 0; }
ps. The standard container classes vector, deque and list fulfill these requirements. By default, if no container class is specified for a particular stack class instantiation, the standard container deque is used.
參考資料:http://www.cplusplus.com/reference/stack/stack/
參考資料:http://www.cplusplus.com/reference/stack/stack/
留言
張貼留言