Skip to content

Latest commit

 

History

History

STL Resources

  • In STL mainly we are having
    1. Algorithm : Algorithm act on containers and provide means for various operations for the contents of the containers
    2. Containers : Containers or container classes store objects and data.
    3. Functions : Functors allow the working of the associated function to be customized with the help of parameters to be passed.
    4. Iterators : Iterators are used for working upon a sequence of values. They are the major feature that allow generality in STL.

Algorithm:

  1. Sorting : sort(startaddress, endaddress)

  2. Searching : binary_search(startaddress,endaddress, valuetofind):- Returns : true if an element equal to valuetofind is found, else false.

  3. Important STL Algorithms

  • sort(first_iterator, last_iterator) – To sort the given vector.
  • reverse(first_iterator, last_iterator) – To reverse a vector.
  • max_element (first_iterator, last_iterator) – To find the maximum element of a vector.
  • min_element (first_iterator, last_iterator) – To find the minimum element of a vector.
  • accumulate(first_iterator, last_iterator, initial value of sum) – Does the summation of vector elements
  • count(first_iterator, last_iterator,x) – To count the occurrences of x in vector.
  • find(first_iterator, last_iterator, x) – Returns an iterator to the first occurence of x in vector and points to last address of vector ((name_of_vector).end()) if element is not present in vector.
  • binary_search(first_iterator, last_iterator, x) – Tests whether x exists in sorted vector or not.
  • 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’.
  1. Useful Array algorithms
  2. Partition Operations
  1. Vector
  2. List
  3. Deque
  4. Array
  5. Forward List