algorithm library
TRANSCRIPT
ALGORITHM LIBRARYDefines Standard Template Library (STL) container template functions that perform algorithms.
AGENDAWhat’s algorithm library?Why algorithm library?Functions.
Sort Function.Count Function.Find Function.Search Function.Other Functions.
Tips and Tricks
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
WHY ALGORITHM LIBRARY?What’s the output ?
Why ??
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);
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);
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();
11321-SORT! SORT!! AND SORT!!!
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.
11321-SORT! SORT!! AND SORT!!!
ascending order of their modulo 2
descending order of their values “even numbers”
ascending order of their modulo 2
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())
11942 - LUMBERJACK SEQUENCING
11942 - LUMBERJACK SEQUENCING
OTHER FUNCTIONS..binary_searchmax_elementmin_elementreverse_copyuniquefor_eachcount_iffill
REFERENCESCplusplus.commsdn.Microsoft.comCppreference.com
ANY QUESTIONS ?!