codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ algorithms

C++ algorithms

sort, find, count and more.

Include algorithm. They work on iterator ranges: sort, reverse, find, count, max_element.

Example code

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  vector<int> v = {5, 2, 9, 1};
  sort(v.begin(), v.end());
  for (int x : v) cout << x << " ";
  cout << *max_element(v.begin(), v.end()) << endl;
  return 0;
}

Run this code in the online editor

← C++ iteratorsC++ namespaces →