Stl Algorithms - C P P

  • #include <algorithm> => Library to include
  • binary_search(var.begin(), var.end(), val) => Returns boolean value true if the given value if present in the given vector
  • lower_bound(var.begin(), var.end(), val) - var.begin() => Returns lower bound iterator to the given value
  • upper_bound(var.begin(), var.end(), val) - var.begin() => Returns upper bound iterator to the given value
  • max(val1, val2) => Returns max of both
  • max({val1, val2, val3}) => Returns max or more than 2 values without doing multiple max function
  • min(val1, val2) => Returns minimum of both
  • swap(var1, var2) => Swaps value of both variables
  • reverse(var.begin(), var.end()) => Reverses the given string
  • rotate(var.begin(), var.begin() + 1, var.end()) => Rotates elements, Given start value, number of elements to rotate and end value
  • lower_bound(var.begin(), var.end()) => Sorts the vector using intro sort method which is a combination of quick sort, heap sort, insertion sort
  • sqrt(n) => Find square root of the number
  • sqrtl(n)
Share: