In this algorithm, you compute the index that each

integer will have in the sorted array. To do so, you construct an array of indices with

each element set initially to zero. Then you loop through the integers in the array, in-

crementing the index of larger integers by one.

For example, you have the following array:

3 2 1 5 4

In the rst pass, we will increment each index holding a value greater than 3. After

nishing the rst pass, the indices array will be equal to:

0 0 0 1 1

After nishing the second pass, the indices array will be equal to:

1 0 0 2 2

After the nth pass, the indices array will be equal to:

2 1 0 4 3

what's wrong with this.

public class indexSort{ public static int[] indexa(int[] x){ int[] y; y = new int[x.length]; for(int i=0;i<x.length;i++){ for(int j=1;j<x.length;j++){ if((x[i]<x[j])) { y[j]=y[j]+1; } } } return y; } public static void main(String[] args) { int [] x = {3,2,0,5,4}; System.out.print(indexa(x)); } }

This post has been edited by **javatized**: 28 October 2009 - 07:59 AM