b. Stack push(value): Pushes an element to the top. pop(): Removes the top element. top(): Returns the top element. empty(): Returns true if stack is empty. size(): Returns the number of elements.
c. Queue push(value): Adds an element to the end. pop(): Removes the front element. front(): Returns the front element. back(): Returns the last element. empty(): Returns true if queue is empty. size(): Returns the number of elements.
d. Deque (Double-Ended Queue) push_front(value): Adds element at the front. push_back(value): Adds element at the back. pop_front(): Removes element from the front. pop_back(): Removes element from the back. front(): Returns the front element. back(): Returns the back element. size(): Returns the number of elements. empty(): Returns true if deque is empty.
e. Set (Unique Elements) insert(value): Inserts an element. erase(value): Removes an element. find(value): Finds an element (returns iterator). size(): Returns the number of elements. empty(): Returns true if set is empty. count(value): Returns the count of elements (either 0 or 1). lower_bound(value): Returns the iterator to the first element not less than the given value. upper_bound(value): Returns the iterator to the first element greater than the given value.
f. Map (Key-Value Pairs) insert({key, value}): Inserts a key-value pair. erase(key): Removes the key-value pair. find(key): Finds an element by key (returns iterator). size(): Returns the number of elements. empty(): Returns true if map is empty. at(key): Returns the value associated with key (throws exception if not found). lower_bound(key): Returns the iterator to the first element not less than the given key. upper_bound(key): Returns the iterator to the first element greater than the given key.
g. Unordered Set insert(value): Inserts an element. erase(value): Removes an element. find(value): Finds an element. count(value): Returns the number of occurrences of the value.
h. Unordered Map insert({key, value}): Inserts a key-value pair. erase(key): Removes a key-value pair. find(key): Finds an element by key. at(key): Returns the value associated with key. count(key): Returns the number of occurrences of the key.
b. Searching binary_search(begin, end, value): Returns true if value exists in the range. lower_bound(begin, end, value): Returns an iterator to the first element not less than value. upper_bound(begin, end, value): Returns an iterator to the first element greater than value. find(begin, end, value): Returns an iterator to the first occurrence of value.
c. Min/Max min(a, b): Returns the smaller of two values. max(a, b): Returns the larger of two values. min_element(begin, end): Returns an iterator to the smallest element. max_element(begin, end): Returns an iterator to the largest element.
d. Accumulate accumulate(begin, end, init): Returns the sum of elements in a range. partial_sum(begin, end, result): Computes the partial sum of elements.
e. Other Algorithms next_permutation(begin, end): Re-arranges elements into the next lexicographically greater permutation. prev_permutation(begin, end): Re-arranges elements into the previous lexicographically smaller permutation. rotate(begin, middle, end): Rotates the range [begin, end) so that the first element becomes the element at position middle.
b. Pair make_pair(a, b): Creates a pair. first: Returns the first element of the pair. second: Returns the second element of the pair.
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
for (int v : vec) {
cout << v << " "; }
cout << "\\n";
vec.pop_back();
cout << "Size after pop: " <<
vec.size() << "\\n";}
#include <iostream>
#include <map>
using namespace std;
int main() {
map<int, string> m; m
[1] = "One";
m[2] = "Two";
for (auto& entry : m) {
cout << entry.first << ": " <<
entry.second << "\\n"; }}
#include <iostream>
#include <set>
using namespace std;
int main() {
set<int> s;
s.insert(10);
s.insert(20);
s.insert(10); // Duplicate element is ignored
for (int elem : s) {
cout << elem << " ";
}
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> vec = {5, 2, 8, 3, 1}; sort(vec.begin(), vec.end());
// Sorts in ascending order
for (int v : vec) {
cout << v << " ";
}
}
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
unordered_map<char, int> freq;
for (char c : s)
freq[c]++;
for (auto &p : freq) {
cout << p.first << " -> " << p.second << endl;
}
return 0;
}