Created
May 2, 2020 11:55
-
-
Save yasukei/32f7ac3582d6720ba8ac09f1f03794ab to your computer and use it in GitHub Desktop.
std::queue
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 <list> | |
#include <deque> | |
#include <queue> | |
int main() | |
{ | |
std::deque<int> d = { 1, 2, 3 }; | |
std::list<int> l = { 4, 5 }; | |
std::queue<int> q1(std::move(d)); | |
std::queue<int, std::list<int>> q2(std::move(l)); | |
auto print = [&]() { | |
std::cout << "q1.empty(): " << q1.empty() << "\n"; | |
std::cout << "q1.size(): " << q1.size() << "\n"; | |
std::cout << "q2.empty(): " << q2.empty() << "\n"; | |
std::cout << "q2.size(): " << q2.size() << "\n"; | |
}; | |
std::cout << "\n[Initial state]\n"; | |
print(); | |
std::cout << "\n[After push()]\n"; | |
q1.push(10); | |
q2.push(100); | |
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] | |
q1.empty(): 0 | |
q1.size(): 3 | |
q2.empty(): 0 | |
q2.size(): 2 | |
[After push()] | |
q1.empty(): 0 | |
q1.size(): 4 | |
q2.empty(): 0 | |
q2.size(): 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment