Professional Documents
Culture Documents
Standard Template Library: Fall-2020
Standard Template Library: Fall-2020
PROGRAMMING
Fall- 2020
University of Engineering
Mardan & Technology
Department of Computer Software Engineering
• Selection sort
is a simple sorting algorithm in which the list is divided into two parts,
the sorted part at the left end and the unsorted part at the right end.
Initially, the sorted part is empty and the unsorted part is the entire list.
• The smallest element is selected from the unsorted array and swapped
with the leftmost element, and that element becomes a part of the
sorted array. This process continues moving unsorted array boundaries
by one element to the right.
Bubble Sort Algorithm
• Bubble Sort is an elementary sorting algorithm, which works by repeatedly exchanging adjacent elements,
if necessary. When no exchanges are required, the file is sorted.
• We assume list is an array of n elements. We further assume that swap function swaps the values of the
given array elements.
• Step 1 − Check if the first element in the input array is greater than the next element in the array.
• Step 2 − If it is greater, swap the two elements; otherwise move the pointer forward in the array.
• Step 3 − Repeat Step 2 until we reach the end of the array.
• Step 4 − Check if the elements are sorted; if not, repeat the same process (Step 1 to Step 3) from the last
element of the array to the first.
• Step 5 − The final output achieved is the sorted array.
• Insertion Sort Algorithm
Standard Template Library (STL) mainly consists of three components which are mentioned
below:
1) Containers
Containers are class templates which organizes stored data in memory. There
are various types of container class available like Array, Stack, Vector, List,
Queue etc.
2) Algorithms
Algorithms are various processes that act on containers. These processes
include different sortings, copy, search, merge, modify etc.
3) Iterators
Iterators are a generalization of the concept of pointers: they point to elements
in a container. It can perform the operations like begin, end, next, prev etc.
Standard Template Library
Containers
(Sequence Containers)
Containers
(Associative Containers)
Associative Containers use keys to access data. Keys are numbers assigned by containers.
a) Set: Stores only the key objects Only one key of each value allowed
b) Multiset: Stores only the key objects Multiple key values allowed
c) Map: Associates key object with value object Only one key of each value allowed
d) multimap Associates key object with value object Multiple key values allowed
Standard Template Library
Container functions
Container Adapters
(Special-purpose containers have simpler interfaces than the more general containers)
Algorithms
Algorithms cont…
Iterators
Similar to pointers, iterators are entities that are used to access individual data items (elements) in a container.