algorithm library

17
ALGORITHM LIBRARY Defines Standard Template Library (STL) container template functions that perform algorithms.

Upload: ahmed-mohsen-hassan

Post on 19-Aug-2015

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithm Library

ALGORITHM LIBRARYDefines Standard Template Library (STL) container template functions that perform algorithms.

Page 2: Algorithm Library

AGENDAWhat’s algorithm library?Why algorithm library?Functions.

Sort Function.Count Function.Find Function.Search Function.Other Functions.

Tips and Tricks

Page 3: Algorithm Library

WHAT’S ALGORITHM LIBRARY?

STL

Containers

Sequence containers

Vector

List

Containeradaptor

Stack

Queue

Associative

containers

Set

Map

Unordered associative containers

Unordered Set

Unordered Map

Algorithms

Non-modifying sequence operations

Max/Min

Find

Count

Modifying sequence operations

Sort

Reverse

Next_permutation

Page 4: Algorithm Library

WHY ALGORITHM LIBRARY?What’s the output ?

Why ??

Page 5: Algorithm Library

FUNCTIONS

Countvector <int>

numbers={2,1,3,1,17,2,1,3,5,6};

int target = 1;for (int i = 0; i < 10; i++)if(numbers[i] ==target)

count_ ++;

count(numbers.begin(),numbers.end(),1);

Page 6: Algorithm Library

FUNCTIONS

Findvector <int>

numbers={2,1,3,1,17,2,1,3,5,6};

int target = 1, index = -1;for (int i = 0; i < 10; i++) if(numbers[i] == target)

{index = i; break; }

find(numbers.begin(),numbers.end(),1);

Page 7: Algorithm Library

FUNCTIONS

Sortvector <int> numbers={2,-

1,3,10,17,2,5};

for (int i = 0; i < 7; i++) for (int j = i; j < 7; j++)

if (numbers[i] >numbers[j]) swap(numbers[i],numbers[j]);

Sort(numbers.begin(),numbers.end();

Page 8: Algorithm Library

11321-SORT! SORT!! AND SORT!!!

Page 9: Algorithm Library

11321-SORT! SORT!! AND SORT!!!Given N numbers. You will have to sort them in ascending order of their modulo 2 values, If there is a tie between even numbers sort them in descending order of their values, If there is a tie between odd numbers sort them in ascending order of their values.

Page 10: Algorithm Library

11321-SORT! SORT!! AND SORT!!!

ascending order of their modulo 2

descending order of their values “even numbers”

ascending order of their modulo 2

Page 11: Algorithm Library

FUNCTIONS

Reversevector <int>

numbers={2,1,3,1,17,2,1,3,5,6};

int size = number.size();for (int i = 0; i < size/2; i++)

swap(numbers[i],numbers[size-i-1])

reverse(numbers.begin(),numbers.end())

Page 12: Algorithm Library

11942 - LUMBERJACK SEQUENCING

Page 13: Algorithm Library

11942 - LUMBERJACK SEQUENCING

Page 14: Algorithm Library

OTHER FUNCTIONS..binary_searchmax_elementmin_elementreverse_copyuniquefor_eachcount_iffill

Page 16: Algorithm Library

ANY QUESTIONS ?!

Page 17: Algorithm Library

THANK YOU For any questions Contact me at:

G-mail: [email protected]