FUNCTION
Smallest
Finds the smallest value of order k in the given array.
Interface
#include <codecogs/statistics/moments/smallest.h>
using namespace Statistics::Moments;
This function uses the Hoare selection algorithm to return the k-th smallest value in a data set. If on input the order k is 1 the minimum entry is sought, while if k is equal to the size of the array, the maximum is calculated.
Example:
#include <codecogs/statistics/moments/smallest.h>
#include <iostream>
int main()
{
int x[6] = {1, 5, 2, 3, 8, 7},
small = Stats::Moments::smallest<int>(6, x, 4);
std::cout << "The 4th smallest value of the array is: " << small;
std::cout << std::endl;
return 0;
}
Output:
The 4th smallest value of the array is: 5
References
SUBSET, a library of C++ combinatorial routines, www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html
Parameters
n
the size of the array
data
an array of numerical data for which you want to determine the k-th smallest value
k
the order of the largest value to return
Returns
the k-th smallest value in the given data set
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.