I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 0.40
sub units 0.00
+
0

Rank

Calculates the rank of a number in a list of numbers.
Controller: CodeCogs

Interface

C++

Rank

 
template<class T> intrankintx
intn
T*data
boolascending = true )
Returns the rank of a number in a list of numbers. The rank of a number is its size relative to other values in a list. (If you were to sort the list, the rank of the number would be its position.) Rank gives duplicate numbers the same rank. However, the presence of duplicate numbers affects the ranks of subsequent numbers. For example, in a list of integers sorted in ascending order, if the number 10 appears twice and has a rank of 5, then 11 would have a rank of 7 (no number would have a rank of 6).

Example 1

#include <codecogs/statistics/moments/rank.h>
#include <iostream>
int main()
{
  double x[5] = {4 , 5 , 8 , 6 , 3};
  double rka = Stats::Moments::rank(4, 5, x);
  double rkd = Stats::Moments::rank(4, 5, x, false);
  std::cout << "The rank of 4 in the array x sorted in ascending order is: " << rka << std::endl;
  std::cout << "The rank of 4 in the array x sorted in descending order is: " << rkd << std::endl;
  return 0;
}
Output:
The rank of 4 in the array x sorted in ascending order is: 2
The rank of 4 in the array x sorted in descending order is: 4

Parameters

xis the number whose rank you want to find
nthe size of the array
datathe actual array data
ascendingDefault Value = true

Returns

the rank of a number in a list of numbers

Authors

Anca Filibiu (August 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.