Package dsa
Class Inversions
- java.lang.Object
-
- dsa.Inversions
-
public class Inversions extends Object
This library to count the number of inversions in an array. An inversion in an arraya
is a pair(i, j)
of indicies such thati
<j
anda [i]
>a[j]
.
-
-
Constructor Summary
Constructors Constructor Description Inversions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
count(double[] a)
Returns the number of inversions in the arraya
.static long
count(int[] a)
Returns the number of inversions in the arraya
.static long
count(Comparable[] a)
Returns the number of inversions in the arraya
, according to the natural order of its objects.static long
count(Object[] a, Comparator c)
Returns the number of inversions in the arraya
, according to the order induced by the comparatorc
.static void
main(String[] args)
Unit tests the library.
-
-
-
Method Detail
-
count
public static long count(Comparable[] a)
Returns the number of inversions in the arraya
, according to the natural order of its objects.- Parameters:
a
- the array.- Returns:
- the number of inversions in the array
a
, according to the natural order of its objects.
-
count
public static long count(Object[] a, Comparator c)
Returns the number of inversions in the arraya
, according to the order induced by the comparatorc
.- Parameters:
a
- the array.c
- the comparator to determine the order of the array.- Returns:
- the number of inversions in the array
a
, according to the order induced by the comparatorc
.
-
count
public static long count(int[] a)
Returns the number of inversions in the arraya
.- Parameters:
a
- the array.- Returns:
- the number of inversions in the array
a
.
-
count
public static long count(double[] a)
Returns the number of inversions in the arraya
.- Parameters:
a
- the array.- Returns:
- the number of inversions in the array
a
.
-
main
public static void main(String[] args)
Unit tests the library.- Parameters:
args
- the command-line arguments.
-
-