Created
May 6, 2020 12:28
-
-
Save yasukei/6fd6290aa8c71e7ad89727f9a5ef1c4c to your computer and use it in GitHub Desktop.
std::stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <deque> | |
#include <list> | |
#include <vector> | |
#include <stack> | |
int main() | |
{ | |
std::deque<int> d = { 1, 2, 3 }; | |
std::list<int> l = { 4, 5 }; | |
std::vector<int> v = { 6 }; | |
std::stack<int> s1(std::move(d)); | |
std::stack<int, std::list<int>> s2(std::move(l)); | |
std::stack<int, std::vector<int>> s3(std::move(v)); | |
auto print = [&]() { | |
std::cout << "s1.empty(): " << s1.empty() << "\n"; | |
std::cout << "s1.size(): " << s1.size() << "\n"; | |
std::cout << "s2.empty(): " << s2.empty() << "\n"; | |
std::cout << "s2.size(): " << s2.size() << "\n"; | |
std::cout << "s3.empty(): " << s3.empty() << "\n"; | |
std::cout << "s3.size(): " << s3.size() << "\n"; | |
}; | |
std::cout << "\n[Initial state]\n"; | |
print(); | |
std::cout << "\n[After push()]\n"; | |
s1.push(10); | |
s2.push(100); | |
s3.push(1000); | |
print(); | |
std::cout << "\n[After pop()]\n"; | |
s1.pop(); | |
s2.pop(); | |
s3.pop(); | |
print(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Initial state] | |
s1.empty(): 0 | |
s1.size(): 3 | |
s2.empty(): 0 | |
s2.size(): 2 | |
s3.empty(): 0 | |
s3.size(): 1 | |
[After push()] | |
s1.empty(): 0 | |
s1.size(): 4 | |
s2.empty(): 0 | |
s2.size(): 3 | |
s3.empty(): 0 | |
s3.size(): 2 | |
[After pop()] | |
s1.empty(): 0 | |
s1.size(): 3 | |
s2.empty(): 0 | |
s2.size(): 2 | |
s3.empty(): 0 | |
s3.size(): 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment