0% found this document useful (0 votes)
10 views13 pages

6.1 STL

Uploaded by

hetavimodi2005
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)
10 views13 pages

6.1 STL

Uploaded by

hetavimodi2005
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/ 13

Unit 6

Standard Template Library (STL)

--Prof. S.N.Shelke
Syllabus- Unit 6

 Introduction to STL, STL Components,

 Containers- Sequence container and associative containers, container

adapters,
 Application of Container classes: vector, list,

 Algorithms- basic searching and sorting algorithms, min-max algorithm, set

operations, heap sort,


 Iterators- input, output, forward,bidirectional and random access.

 Object Oriented Programming – a road map to future


Standard Template Library (STL),
Standard Template Library
 In the late 70s Alexander Stepanov first observed that some algorithms

do not depend on some particular implementation of a data structure but


only on a few fundamental semantic properties of the structure
 Developed by Stepanov and Lee at HP labs in 1992

 Become part of the C++ Standard in 1994


Standard Template Library
 The standard template library (STL) contains

 Containers

 Algorithms

 Iterators

 A container is a way that stored data is organized in memory, for example an

array of elements.
 Algorithms in the STL are procedures that are applied to containers to process

their data, for example search for an element in an array, or sort an array.
 Iterators are a generalization of the concept of pointers, they point to elements in

a container, for example you can increment an iterator to point to the next element
in an array
Containers, Iterators, Algorithms

Algorithms use iterators to interact with objects stored


in containers

Container Container
Iterator
Algorithm

Objects Iterator

Algorithm
Iterator Iterator

Algorithm
Containers

 A container is a way to store data, either built-in data types like int and
float, or class objects
 The STL provides several basic kinds of containers
 <vector> : one-dimensional array
 <list> : double linked list
 <deque> : double-ended queue
 <queue> : queue
 <stack> : stack
 <set> : set
 <map> : associative array
Header
Container Description iterator
file
vector is a class that creates a dynamic array allowing
vector <vector> Random access
insertions and deletions at the back.

list is the sequence containers that allow the insertions and


list <list> Bidirectional
deletions from anywhere.

deque is the double ended queue that allows the insertion


deque <deque> Random access
and deletion from both the ends.

set set is an associate container for storing unique sets. <set> Bidirectional

Multiset is an associate container for storing non- unique


multiset <set> Bidirectional
sets.

Map is an associate container for storing unique key-value


map pairs, i.e. each key is associated with only one value(one to <map> Bidirectional
one mapping).

multimap is an associate container for storing key- value


multimap pair, and each key can be associated with more than one <map> Bidirectional
value.
stack It follows last in first out(LIFO). <stack> No iterator
queue It follows first in first out(FIFO). <queue> No iterator
Priority-
First element out is always the highest priority element. <queue> No iterator
Container

 It is an object that actually stores data.

 STL containers are implemented by template classes and therefore can be easily

customized to hold different types of data.

 STL defines 10 containers which are grouped into three category.


Container

Sequence Association Derived


Containers Containers Containers
 Set  Stack
Vector  Multiset  Queue
 Deque  Map Priority_queue
 List  multimap
1. Sequence Containers
 A sequence container stores a set of elements in sequence, in other

words each element (except for the first and last one) is preceded by
one specific element and followed by another, <vector>, <list> and
<deque> are sequential containers
 In an ordinary C++ array the size is fixed and can not change during

run-time, it is also tedious to insert or delete elements.


 Advantage: quick random access

 <vector> is an expandable array that can shrink or grow in size, but still

has the disadvantage of inserting or deleting elements in the middle


Sequence Containers

 <list> is a double linked list (each element has points to its successor

and predecessor), it is quick to insert or delete elements but has slow


random access
 <deque> is a double-ended queue, that means one can insert and

delete elements from both ends, it is a kind of combination between a


stack (last in first out) and a queue (first in first out) and constitutes a
compromise between a <vector> and a <list>
Prof. S. N. Shelke
(Assistant Professor)
Department of Computer Engineering
Sinhgad Academy of Engineering,
Kondhwa, Pune

You might also like