Magic of Algorithm header file in C++

In C++ Algorithm header file contains bountiful magical operations which are very important in competitive programming and take less time to write code.

There are some predefined methods in the algorithm:

1. find(): This method helps to search an element in a vector or array. It will return the address to that particular index. We can calculate the index by subtracting the base address of the array from it.
Syntax:
         auto it = find(arr,arr+n,key);
         int index= it-arr;

2. Upper bound and lower bound: upper_bound() return index to ending index of searched element.
lower_bound() return first index of searched element.

3. reverse(): used to reverse a string
4. swap(): used to swap two values variables
5. sort(): sort an array or vector. By specify first address nd end element.

Map:
begin() – Returns an iterator to the first element in the map
end() – Returns an iterator to the theoretical element that follows last element in the map
size() – Returns the number of elements in the map
max_size() – Returns the maximum number of elements that the map can hold
empty() – Returns whether the map is empty
pair insert(keyvalue, mapvalue) – Adds a new element to the map
erase(iterator position) – Removes the element at the position pointed by the iterator
erase(const g)– Removes the key value ‘g’ from the map
clear() – Removes all the elements from the map


set:

unique, immutable,sorted, unindexed
  • begin() – Returns an iterator to the first element in the set.
  • end() – Returns an iterator to the theoretical element that follows the last element in the set.
  • size() – Returns the number of elements in the set.
  • max_size() – Returns the maximum number of elements that the set can hold.
  • empty() – Returns whether the set is empty.

Comments

Popular posts from this blog

Intellect Interview Experience

Google

Accolite digital Interview experience