-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquick_select.h
39 lines (34 loc) · 1.35 KB
/
quick_select.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef CPP_ALGORITHM_QUICK_SELECT_H
#define CPP_ALGORITHM_QUICK_SELECT_H
#include <vector>
namespace QuickSelect
{
/**
* \brief Find the k-th smallest element in an array.
* \param array an array of integers
* \param k the k-th smallest
* \return the k-th smallest element
*/
auto FindKthSmallestElement(std::vector<int>& array, int k) -> int;
/**
* \brief Find the k-th smallest element in an array.
* \param array an array of integers
* \param k the k-th smallest
* \return the k-th smallest element
*/
auto FindKthLargestElement(std::vector<int>& array, int k) -> int;
/**
* \brief QuickSelect is an algorithm used to select the k-th smallest (or largest) element in an unordered list of
* elements.
* \details It is a variation of QuickSort algorithm and works by partitioning the list into two sub lists around a
* pivot element, with elements less than or equal to the pivot on one side and elements greater than the pivot on
* the other.
* \param array the array to search
* \param left the left index of the array
* \param right the right index of the array
* \param k the index of the k-th element
* \return the k-th element in the array
*/
auto QuickSelectAlgorithm(std::vector<int>& array, int left, int right, int k) -> int;
}
#endif