Day 28: STL – Introduction to Standard Template Library
The Standard Template Library (STL) is one of the most powerful Characteristics in C++. it provides ready-to-use information structures and Procedures devising coding quicker and further efficient
๐น topics to cover:
what is stl
Parts of stl:
containers
iterators
Procedures
types of containers:
sequence containers (vector number deque)
associative containers (set map)
unordered containers (unordered_set unordered_map)
container Adjustors (stack line up priority_queue)
๐ examples:
1. Using vector
cpp
Copy
Edit
#include
#include
using namespace std;
int main() {
vector v = {1 2 3 4};
v.Send_back(5); // Add element
for (int i : v)
cout << i << " "; // Output: 1 2 3 4 5
}
2. exploitation set
cpp
copy
edit
#include
#include
using namespace std;
int main() {
set s;
sinsert(4);
sinsert(2);
sinsert(4); // parallel leave work neglected for (int one : s)
cout << one << " "; // output: ii 4
}
3. Using map
cpp
Copy
Edit
#include
#include
using namespace std;
int main() {
map int=""> age;
age["Alice"] = 30;
age["Bob"] = 25;
for (auto it : age)
cout << it.first << ": " << it.second << endl;
}
๐งช practise Tasks:
Use vector to store and sort a list of integers.
Use set to store unique names from Operator input.
Use map to count the frequency of characters in a string.
Make a program that uses stack or queue.
✅ Goals for Today:
Understand the power of STL.
Be able to use basic STL containers: vector set map stack.
Use STL Procedures like sort() find().
>
Comments
Post a Comment