Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- #include <queue>
- #include <stack>
- #include<unordered_set>
- #include<unordered_map>
- using namespace std;
- int main()
- {
- /* array */
- array<int,5> a = { 1, 2, 3, 4, 5 };
- for ( auto it = a.begin(); it != a.end(); ++it )
- {
- std::cout << ' ' << *it;
- }
- std::cout << '\n';
- /* queue*/
- queue<int> s;
- s.push(1);
- s.push(2);
- s.push(3);
- s.push(4);
- s.push(5);
- cout << s.size() <<endl; //Affiche taille : 5
- cout << s.front() <<endl; //Affiche 1er element : 1
- cout << s.back() <<endl;//Affiche dernier elem : 5
- std::cout << '\n';
- /* stack */
- stack<int> z;
- z.push(1);
- z.push(2);
- z.push(3);
- z.push(4);
- z.push(5);
- cout << z.size() <<endl;//Affiche la ttaille du stack : 5
- cout << z.top() <<endl; //Affice le dernier element : 5
- std::cout << '\n';
- /* deque*/
- deque<int> d(4,5); // deque de 4 entiers valant 5
- d.push_front(2);
- d.push_back(8);
- for(int i(0); i<d.size(); ++i)
- cout << d[i] << " "; //Affiche 2 5 5 5 5 8
- std::cout << '\n';
- /* priority_queue<int> pq;*/
- priority_queue<int> pq;
- for (int i = 0; i < 5; i++)
- {
- pq.push(a[i]);
- }
- // print priority queue
- cout << "Priority Queue: ";
- while (!pq.empty())
- {
- cout << pq.top() << ' ';
- pq.pop();
- }
- std::cout << '\n';
- /* unordered_set */
- unordered_set<string> stringSet;
- stringSet.insert("C++");
- stringSet.insert("en");
- stringSet.insert("coder");
- stringSet.insert("j'aime");
- string key = "slow";
- cout << "\nTout les elements : " << endl;
- unordered_set<string>::iterator itr;
- for (itr = stringSet.begin(); itr != stringSet.end();itr++)
- {
- cout << (*itr) << endl;
- }
- std::cout << '\n';
- /* unordered_map */
- unordered_map<string, int> u_carte;
- // Insertion des clés
- u_carte["souris"] = 10;
- u_carte["chien"] = 20;
- u_carte["gros chien"] = 30;
- // iteration sur la unordered map
- for (auto x : u_carte)
- {
- cout << x.first << " " <<
- x.second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement