Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

STL Algorithms

This document discusses STL algorithms and adaptors. It introduces common STL algorithms like copy, find, sort, and their uses. It also covers iterator adaptors that allow algorithms to insert elements into containers, like back_inserter and front_inserter. The document provides examples of using algorithms like copy and iterator adaptors to insert elements into vectors.

Uploaded by

Hamid Kisha
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)
9 views

STL Algorithms

This document discusses STL algorithms and adaptors. It introduces common STL algorithms like copy, find, sort, and their uses. It also covers iterator adaptors that allow algorithms to insert elements into containers, like back_inserter and front_inserter. The document provides examples of using algorithms like copy and iterator adaptors to insert elements into vectors.

Uploaded by

Hamid Kisha
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/ 51

STL ALGORITHMS

Unnecessary Subtitle
Algorithms

-ithms?

STL Algorithms
The STL Hierarchy

ITERATORS

CONTAINERS

STL Algorithms
The STL Hierarchy

ALGORITHMS

ITERATORS

CONTAINERS

STL Algorithms
STL Algorithms

#include <algorithm>

#include <numeric>

STL Algorithms
Calculating Averages

(code)

STL Algorithms
Why Algorithms?

STL Algorithms
Why Algorithms?

 don’t duplicate code

STL Algorithms
Why Algorithms?

 don’t duplicate code


 write correct code

STL Algorithms
Why Algorithms?

 don’t duplicate code


 write correct code

 write efficient code

STL Algorithms
Why Algorithms?

 don’t duplicate code


 write correct code

 write efficient code

 write clear code

STL Algorithms
Magic Squares

2 7 6
9 5 1
4 3 8

STL Algorithms
Magic Squares

2 7 6
9 5 1
4 3 8

STL Algorithms
Magic Squares

2 7 6
9 5 1
4 3 8

STL Algorithms
Magic Squares

2 7 6
9 5 1
4 3 8

STL Algorithms
Magic Squares

2 7 6
9 5 1
4 3 8

2 7 6 9 5 1 4 3 8

STL Algorithms
Permutations

123

STL Algorithms
Permutations

123
132
213
231
312
321
STL Algorithms
Magic Squares

(code)

STL Algorithms
Why Algorithms?

 don’t duplicate code


 write correct code

 write efficient code

 write clear code

STL Algorithms
Algorithm Rules

STL Algorithms
Algorithm Rules

Make sure you have


enough space!

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

0 0 0 0 0 0

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

27 0 0 0 0 0

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

27 100 0 0 0 0

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

27 100 96 0 0 0

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

27 100 96 7 13 66

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

0 0

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

27 0

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

27 100

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

27 100

STL Algorithms
Algorithm Rules

copy(A.begin(), A.end(), B.begin());

27 100 96 7 13 66

27 100

STL Algorithms
Set Union

(code)

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

push_back

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

27

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

27 100

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

27 100 96

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

27 100 96 7

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

27 100 96 7 13

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

27 100 96 7 13 66

STL Algorithms
back_inserter

copy(A.begin(), A.end(), back_inserter(B));

27 100 96 7 13 66

27 100 96 7 13 66

STL Algorithms
Adaptors

STL Adaptors
Adaptors

STL Adaptors
Adaptors

STL Adaptors
Adaptors

STL Adaptors
Adaptors

STL Adaptors
Iterator Adaptors

 back_inserter
 front_inserter
 inserter

STL Adaptors
Iterator Adaptors

 back_inserter
 front_inserter
 inserter

 istream_iterator
 ostream_iterator

STL Adaptors
Iterator Adaptors

(code)

STL Adaptors

You might also like