Here is the most used of the many functions that STL provides:
sort(first_iterator, last_iterator)
- It sorts the elements in ascending order by default. To sort it in descending order we have to pass comparison function as the third parameter. greater<int>() can be used to achieve that purpose.
reverse(first_iterator, last_iterator)
- It reverses the vector
*max_element(first_iterator, last_iterator)
- It returns the maximum element of the vector
*min_element(first_iterator, last_iterator)
- It returns the minimum element of the vector
accumulate(first_iterator, last_iterator, initial sum value)
- It returns the sum of the elements plus the initial sum value
count(first_iterator, last_iterator, element)
- It returns the number of times element occurred in the given vector
find(first_iterator, last_iterator, element)
- It returns the element if found else end of the vector
binary_search(first_iterator, last_iterator, element)
- It performs binary search and finds out whether the element is present in vector or not(vector must be sorted beforehand)
lower_bound(first_iterator, last_iterator, x)
- returns an iterator pointing to the first element in the range [first, last) which has a value not less than ‘x’.
upper_bound(first_iterator, last_iterator, x)
- returns an iterator pointing to the first element in the range [first, last) which has a value greater than ‘x’.
array.erase( index to be deleted)
- It will remove the element at given index and resizes the array
copy_n(source_array, no_of_elements_to_copy, destination_array)
- It will copy no_of_elements_to_copy from source array to destination array.
sort(first_iterator, last_iterator)
- It sorts the elements in ascending order by default. To sort it in descending order we have to pass comparison function as the third parameter. greater<int>() can be used to achieve that purpose.
reverse(first_iterator, last_iterator)
- It reverses the vector
*max_element(first_iterator, last_iterator)
- It returns the maximum element of the vector
*min_element(first_iterator, last_iterator)
- It returns the minimum element of the vector
accumulate(first_iterator, last_iterator, initial sum value)
- It returns the sum of the elements plus the initial sum value
count(first_iterator, last_iterator, element)
- It returns the number of times element occurred in the given vector
find(first_iterator, last_iterator, element)
- It returns the element if found else end of the vector
binary_search(first_iterator, last_iterator, element)
- It performs binary search and finds out whether the element is present in vector or not(vector must be sorted beforehand)
lower_bound(first_iterator, last_iterator, x)
- returns an iterator pointing to the first element in the range [first, last) which has a value not less than ‘x’.
upper_bound(first_iterator, last_iterator, x)
- returns an iterator pointing to the first element in the range [first, last) which has a value greater than ‘x’.
array.erase( index to be deleted)
- It will remove the element at given index and resizes the array
copy_n(source_array, no_of_elements_to_copy, destination_array)
- It will copy no_of_elements_to_copy from source array to destination array.
Comments
Post a Comment