12985 - Counting Inversions   

Description

Write a function to take two input parameters: an integer array a[] and its size n.  The function should return the number of inversions in a[0..n-1].  The number of inversions in an array a[0..n-1] is the number of index pairs (i,j) such that i<j but a[i]>a[j].

 

Write a driver program to get an input array and then pass it to your function. Again, try to organize your program into functions. You may assume that the array size is no more than 20.

E.g.

int inversion(...){

...

return ....

}

 

main () {

...

inversion(...);

...

}

Input

Integer array's size n, followed by its values

Output

The number of inversions in a[0..n-1]

Sample Input  Download

Sample Output  Download

Tags




Discuss