PDA

View Full Version : Java bubble sort Need help!


Mirugan
Oct 29, 2013, 11:28 AM
//I need to know what is wrong with this code. It does compile but I don't think it's working properly

class Bubblesort
{
public static void main(String[] args)
{
int n[] = {16, 100, 205, 8, 1, 3, 2, 5, 7, 6, 15, 10, 14};
int l = n.length;
int I,a,t;
System.out.print("Given number : ");
for (i = 0;i < l;i++)
{
System.out.print(" " + n[i]);
}
System.out.println("\n");
System.out.print("Accending order number : ");
for (i=1; I < l; I++)
{
for (i=0;i<l-i;i++)
{
if (n[i] > n[i+1])
{
int temp = n[i];
n[i] = n[i+1];
n[i+1] = temp;
}
}
}
for(i=0;i<l;i++){
System.out.print(" " + n[i]);
}
}
}

Scleros
Nov 30, 2013, 08:38 AM
Add some temporary print statements so you can see the value of 'i' for both outer and inner loops as the program runs.