i'm trying to sort this array in special method by :

- Counting the number of smaller elements to find the correct position i.

– If the element is in its correct position, move to the succeeding element.

– Otherwise, swap the current element with the one found in position i.

– Repeat the previous steps till you reach the last element.

So i did this code but something wrong so please help :

public class Ass {

public static void swap(int [] x) {

int i = 0 ;

while (i<x.length){

for (int j = 0 ; j<x.length ; j++){

int b = 0 ;

if ( x[i] > x[j] ) {

b++ ;

}

if (b!=0) {

int tmp = x[i] ;

x[i]=x[b] ;

x[b]= tmp ;

}

}

i++ ;

}

}

public static void main (String [] args) {

int [] array = {5,7,3,6,9} ;

swap(array) ;

for (int k = 0 ; k<array.length ; k++)

System.out.print(array[k] + " ");

}

}