- The C Standard Library
- The C Standard Library

- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>

- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>

- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ Library - <algorithm>

## Introduction to algorithm

The **algorithm** library provides several functions that can be used for a variety of purposes, for instance searching, sorting, counting, manipulating and so on. These functions operate on ranges of elements and the range is defined as *[first, last)*.

## Functions from <algorithm>

Below is list of all methods from <algorithm> header.

### Member functions

Sr.No. | Method & Description |
---|---|

1 | algorithm::adjacent_find()
Finds the first occurrence of two consecutive elements that are identical and returns an iterator pointing to the first element if identical element exists consecutively otherwise returns an iterator pointing to the last element. |

2 | algorithm::adjacent_find()
Finds the first occurrence of two consecutive elements that are identical and returns an iterator pointing to the first element if identical element exists consecutively otherwise returns an iterator pointing to the last element. |

3 | algorithm::all_of()
Returns true if |

4 | algorithm::any_of()
Returns true if |

5 | algorithm::binary_search()
Tests whether value exists in sorted sequence or not. |

6 | algorithm::binary_search()
Tests whether value exists in sorted sequence or not. |

7 | algorithm::copy()
Copies a range of elements to a new location. |

8 | algorithm::copy_backward()
Copies a range of elements to a new location in backward order. |

9 | algorithm::copy_if()
Copies a range of elements to a new location if predicate returns true for value. |

10 | algorithm::copy_n()
Copies first |

11 | algorithm::count()
Returns the number of occurrences of value in range. |

12 | algorithm::count_if()
Returns the number of occurrences of value from range that satisfies condition. |

13 | algorithm::equal()
Tests whether two sets of element are equal or not. |

14 | algorithm::equal()
Tests whether two sets of element are equal or not. |

15 | algorithm::equal_range()
Returns a range of element that matches specific key. |

16 | algorithm::equal_range()
Returns a range of element that matches specific key. |

17 | algorithm::fill()
Assigns certain value to a range of elements. |

18 | algorithm::fill_n()
Assigns value to the first n elements of the sequence pointed by |

19 | algorithm::fill_n()
Assigns value to the first n elements of the sequence pointed by |

20 | algorithm::find()
Finds the first occurrence of the element. |

21 | algorithm::find_end()
Finds the last occurrence of the element. |

22 | algorithm::find_end()
Finds the last occurrence of the element. |

23 | algorithm::find_first_of()
Returns an iterator to the first element in the range of |

24 | algorithm::find_first_of()
Returns an iterator to the first element in the range of |

25 | algorithm::find_if()
Finds the first occurrence of the element that satisfies the condition. |

26 | algorithm::find_if_not()
Finds the last occurrence of the element that satisfies the condition. |

27 | algorithm::for_each()
Applies provided function on each element of the range. |

28 | algorithm::generate()
Assigns the value returned by successive calls to |

29 | algorithm::generate_n()
Assigns the value returned by successive calls to |

30 | algorithm::generate_n()
Assigns the value returned by successive calls to |

31 | algorithm::includes()
Test whether first set is subset of another or not. |

32 | algorithm::includes()
Test whether first set is subset of another or not. |

33 | algorithm::inplace_merge()
Merges two sorted sequence in-place. |

34 | algorithm::inplace_merge()
Merges two sorted sequence in-place. |

35 | algorithm::is_heap()
Tests whether given sequence is max heap or not. |

36 | algorithm::is_heap()
Tests whether given sequence is max heap or not. |

37 | algorithm::is_heap_until()
Finds the first element from the sequence which violates the max heap condition. |

38 | algorithm::is_heap_until()
Finds the first element from the sequence which violates the max heap condition. |

39 | algorithm::is_partitioned()
Tests whether range is partitioned or not. |

40 | algorithm::is_permutation()
Tests whether a sequence is permutation of other or not. |

41 | algorithm::is_permutation()
Tests whether a sequence is permutation of other or not. |

42 | algorithm::is_sorted()
Tests whether range is sorted or not. |

43 | algorithm::is_sorted()
Tests whether range is sorted or not. |

44 | algorithm::is_sorted_until()
Finds first unsorted element from the sequence. |

45 | algorithm::is_sorted_until()
Finds first unsorted element from the sequence. |

46 | algorithm::iter_swap()
Exchange values of objects pointed by two iterators. |

47 | algorithm::lexicographical_compare()
Tests whether one range is lexicographically less than another or not. |

48 | algorithm::lexicographical_compare()
Tests whether one range is lexicographically less than another or not. |

49 | algorithm::lower_bound()
Finds the first element not less than the given value. |

50 | algorithm::lower_bound()
Finds the first element not less than the given value. |