STL

Standard Template Library

Agenda

1. What/Why we need STL (Standard Template Library) ?

2. Common STL components

3. Problems on STL

2. Algorithms (Sorting, Searching and ...etc)

e.g. Sorting, Searching and ...etc

1. Containers / Data-Structures

e.g. Vectors, Sets, Maps, Queues, Stacks and ...etc

WHAT

What does STL mean?

- It provides High Level Implementation

- For example Queue data-structure

There is no need to handle all its operations

Queue data-structure

Templates in cpp

Agenda

1. What/Why we need STL (Standard Template Library) ?

2. Common STL components

3. Problems on STL

2. Algorithms (Sorting, Searching and ...etc)

e.g. Sorting, Searching and ...etc

1. Containers / Data-Structures

e.g. Vectors, Sets, Maps, Queues, Stacks and ...etc

STL containers/data-structures

Vectors

â—‹ Like array but dynamic

- dynamic means that it has the ability to resize itself automatically

â—‹ Like array but dynamic

CODE

Let's jump into code

Vectors

STL containers/data-structures

- FIFO (First In First Out)

Queues

â—‹ inserted at the back (end) and are deleted from the front

- FIFO (First In First Out)

CODE

Let's jump into code

Queues

STL containers/data-structures

Sets

{1, 3, 4, 3} = {1, 3, 4, 4} = {1, 3, 4 }

1. Each element has to be unique

2. Sorts its elements by default

CODE

Let's jump into code

Sets

STL containers/data-structures

1. Similar to sets, have the same list of

Multiset

2. multiple elements can have the same values (Allow  duplicated)

1. Similar to sets, have the same list of operations

STL containers/data-structures

1. Similar to sets, have the same list of

2. The order of the elements is not sorted

1. Similar to sets, have the same list of operations

unordered_set

STL containers/data-structures

1. Store elements in mapped fashion (Key - Values)

2. Sorted by key

Map

CODE

Let's jump into code

Map

STL containers/data-structures

2. The order of the elements is not sorted

1. Similar to maps, have the same list of operations

unordered_map

STL containers/data-structures

Stack

â—‹ inserted at the top and are deleted from the top

- FILO (First In Last Out)

CODE

Let's jump into code

Stack

STL containers/data-structures

Priority Queue

Elements will be processed based on some criteria

CODE

Let's jump into code

Priority Queue

Agenda

1. What/Why we need STL (Standard Template Library) ?

2. Common STL components

3. Problems on STL

2. Algorithms (Sorting, Searching and ...etc)

e.g. Sorting, Searching and ...etc

1. Containers / Data-Structures

e.g. Vectors, Sets, Maps, Queues, Stacks and ...etc

STL algorithms

Sorting - Searching - Utilities

CODE

Let's jump into code

Sorting - Searching - Utilities