0% found this document useful (0 votes)
8 views

All Stl cpp

The document contains a C++ program demonstrating the use of various Standard Template Library (STL) containers, including unordered_set, vector, set, unordered_multiset, multiset, unordered_map, map, unordered_multimap, queue, stack, deque, priority_queue, and list. Each container is initialized, modified, and printed to the console to showcase its functionality. Additionally, it demonstrates the use of the next_permutation algorithm for generating permutations of a vector.

Uploaded by

rohannstu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

All Stl cpp

The document contains a C++ program demonstrating the use of various Standard Template Library (STL) containers, including unordered_set, vector, set, unordered_multiset, multiset, unordered_map, map, unordered_multimap, queue, stack, deque, priority_queue, and list. Each container is initialized, modified, and printed to the console to showcase its functionality. Additionally, it demonstrates the use of the next_permutation algorithm for generating permutations of a vector.

Uploaded by

rohannstu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

<snippet>

​ <content><![CDATA[
#include <iostream>
#include <unordered_set>
#include <vector>
#include <set>
#include <unordered_multiset>
#include <multiset>
#include <unordered_map>
#include <map>
#include <unordered_multimap>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <algorithm> // For next_permutation

int main() {
// unordered_set
std::unordered_set<int> uset = {1, 2, 3, 4};
uset.insert(5);
std::cout << "unordered_set: ";
for (auto &elem : uset) std::cout << elem << " ";
std::cout << "\n";

// vector
std::vector<int> vec = {10, 20, 30};
vec.push_back(40);
std::cout << "vector: ";
for (auto &elem : vec) std::cout << elem << " ";
std::cout << "\n";

// set
std::set<int> set = {5, 1, 3, 4};
set.insert(2);
std::cout << "set: ";
for (auto &elem : set) std::cout << elem << " ";
std::cout << "\n";

// unordered_multiset
std::unordered_multiset<int> umset = {1, 2, 2, 3};
umset.insert(2);
std::cout << "unordered_multiset: ";
for (auto &elem : umset) std::cout << elem << " ";
std::cout << "\n";

// multiset
std::multiset<int> mset = {5, 1, 3, 3};
mset.insert(3);
std::cout << "multiset: ";
for (auto &elem : mset) std::cout << elem << " ";
std::cout << "\n";

// unordered_map
std::unordered_map<int, std::string> umap = {{1, "one"}, {2, "two"}};
umap[3] = "three";
std::cout << "unordered_map: ";
for (auto &[key, value] : umap) std::cout << key << ":" << value << " ";
std::cout << "\n";

// map
std::map<int, std::string> map = {{1, "A"}, {2, "B"}};
map[3] = "C";
std::cout << "map: ";
for (auto &[key, value] : map) std::cout << key << ":" << value << " ";
std::cout << "\n";

// unordered_multimap
std::unordered_multimap<int, std::string> umm = {{1, "A"}, {1, "B"}};
umm.insert({2, "C"});
std::cout << "unordered_multimap: ";
for (auto &[key, value] : umm) std::cout << key << ":" << value << " ";
std::cout << "\n";

// queue
std::queue<int> q;
q.push(10);
q.push(20);
q.push(30);
std::cout << "queue: ";
while (!q.empty()) {
std::cout << q.front() << " ";
q.pop();
}
std::cout << "\n";

// stack
std::stack<int> stk;
stk.push(100);
stk.push(200);
stk.push(300);
std::cout << "stack: ";
while (!stk.empty()) {
std::cout << stk.top() << " ";
stk.pop();
}
std::cout << "\n";

// deque
std::deque<int> dq = {10, 20, 30};
dq.push_front(5);
dq.push_back(40);
std::cout << "deque: ";
for (auto &elem : dq) std::cout << elem << " ";
std::cout << "\n";

// priority_queue
std::priority_queue<int> pq;
pq.push(3);
pq.push(5);
pq.push(1);
std::cout << "priority_queue: ";
while (!pq.empty()) {
std::cout << pq.top() << " ";
pq.pop();
}
std::cout << "\n";

// list
std::list<int> lst = {100, 200, 300};
lst.push_front(50);
lst.push_back(400);
std::cout << "list: ";
for (auto &elem : lst) std::cout << elem << " ";
std::cout << "\n";

// next_permutation
std::vector<int> perm = {1, 2, 3};
std::cout << "Permutations using next_permutation: ";
do {
for (auto &elem : perm) std::cout << elem << " ";
std::cout << "\n";
} while (std::next_permutation(perm.begin(), perm.end()));

return 0;
}

]]></content>
​ <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
​ <tabTrigger>All_Stl</tabTrigger> -->
​ <!-- Optional: Set a scope to limit where the snippet will trigger -->
​ <scope>source.c++</scope> -->
</snippet>

You might also like