21pd39 - Standard Template Library Documentation
21pd39 - Standard Template Library Documentation
PROGRAMMING -
C++ ASSIGNMENT
NAME : VARSHA S
ROLL NO : 21PD39
DEPARTMENT : AMCS
BRANCH : DATA SCIENCE
SEMESTER : 2
THE C++ STANDARD TEMPLATE LIBRARY
(STL):
2. Associative Containers:
Associative containers implement sorted data
structures that can be quickly searched (O(log n)
complexity).
a. Set
b. Map
c. Multiset
d. Multimap
3. Unordered Associative Containers:
Unordered associative containers implement
unsorted (hashed) data structures that can be quickly
searched ( O(1) amortized, O(n) worst-case
complexity).
a. Unordered set
b. Unordered map
c. Unordered multiset
d. Unordered multimap
4. Container Adaptors:
Container adaptors provide a different
interface for sequential containers.
a. Stack
b. Queue
c. Priority Queue
OPERATIONS OF ITERATORS:
begin()
end()
advance()
next()
prev()
insertor()
1. begin()
This function is used to return the beginning
position of the container.
2. end()
This function is used to return the after end
position of the container.
3. advance()
This function is used to increment the iterator
position till the specified number mentioned in its
arguments.
4. next()
This function returns the new iterator that the
iterator would point after advancing the
positions mentioned in its arguments.
5. prev()
This function returns the new iterator that the
iterator would point after decrementing the
positions mentioned in its arguments.
6. insertor()
This function is used to insert the elements at
any position in the container. It accepts 2
arguments, the container and iterator to position
where the elements have to be inserted.
TYPES OF ITERATORS:
Input Iterators
Output Iterators
Forward Iterators
Bidirectional Iterators
Random Access Iterators
1. INPUT ITERATORS :
Input iterators are the iterators that can be used in
sequential input operations, where each value pointed
by the iterator is read-only once and then the iterator
is incremented.
2. OUTPUT ITERATORS:
Output iterators are considered to be the exact
opposite of input iterators, as they perform the
opposite function of input iterators.
3. FORWARD ITERATORS :
Forward iterators are considered to be
the combination of input as well as output
iterators. It provides support to the functionality of
both of them. It permits values to be both accessed
and modified.
4. BIDIRECTIONAL ITERATORS :
Bidirectional iterators are iterators that can be
used to access the sequence of elements in a range
in both directions (towards the end and towards the
beginning). They are similar to forward iterators,
except that they can move in the backward
direction also, unlike the forward iterators, which can
move only in the forward direction.
Algorithm Operations
Sorting
Searching
Important STL algorithms
Useful Array Algorithms
Partition Operations
Manipulating algorithm
Manipulating algorithm:
Syntax :
1. arr.erase(position to be deleted)
2. arr.erase(unique(arr.begin(),arr.end()),arr.end(
)
3. next_permutation(first_iterator, last_iterator)
4. prev_permutation(first_iterator, last_iterator)
5. distance(first_iterator,desired_position)
Apart from these there are many more algorithm
operations in STL.
EXAMPLE:
sort (first_iterator, last_iterator) :
This function internally uses IntroSort. In more details
it is implemented using hybrid of QuickSort, HeapSort
and InsertionSort. By default, it uses QuickSort but if
QuickSort is doing unfair partitioning and taking more
than N*logN time, it switches to HeapSort and when
the array size becomes really small, it switches to
InsertionSort.
EXAMPLE CODE:
// C++ program to sort an array
int main()
{
Functor f;
int a = 5;
int b = 7;
int ans = f(a, b);
cout<<”The addition of two numbers
are”<<ans;
return 0;
}
https://www.geeksforgeeks.org/the-c-standard-
template-library-stl/
https://www.tutorialspoint.com/cplusplus/
cpp_stl_tutorial.htm
https://www.geeksforgeeks.org/containers-cpp-stl/
https://www.javatpoint.com/cpp-iterators
https://www.geeksforgeeks.org/iterators-c-stl/
https://cplusplus.com/reference/algorithm/
https://www.geeksforgeeks.org/sort-algorithms-the-c-
standard-template-library-stl/
https://docs.microsoft.com/en-us/cpp/standard-
library/function-objects-in-the-stl?
view=msvc-170
https://www.geeksforgeeks.org/functors-in-cpp/
THANK YOU