My insertionSort Program not showing the correct result :'(
Arry is : 5 2 6 1 3
Result will: 1 2 3 5 6
But not Showing Result.
Code is:
public class insertionSort
{
public static void main(String[] args)
{
int data[] ={5,2,6,1,3};
for(int j = 2; j <data.length; j++)
{
int key = data[j];
int i = j - 1;
while(i > 0 && data[i] > key)
{
data[i + 1] = data[i];
i=i-1;
}
data[i + 1] = key;
System.out.print(data[j]+" ");
}
}
}