My Teacher told me that this is the one and only code for Bubble Sort
int a[]={2,3,7,9,8,1,4,5,10,6}; for(int i=0;i<a.length;i++) { for(int j=0;j<a.length-i-1;j++) { if(a[j]>a[j+1]) { int t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } for(int i=0;i<a.length;i++) { System.out.print(a[i]+"\t"); }
But I started the program with a different external circuit -
int b[]={2,3,7,9,8,1,4,5,10,6}; for(int i=0;i<b.length-1;i++) { for(int j=0;j<b.length-i-1;j++) { if(b[j]>b[j+1]) { int t=b[j]; b[j]=b[j+1]; b[j+1]=t; } } } for(int i=0;i<b.length;i++) { System.out.print(b[i]+"\t"); }
Exits - 1st case -
1 2 3 4 5 6 7 8 9 10
The second case is
1 2 3 4 5 6 7 8 9 10
So, now they tell me that my code is wrong, even if my output came correctly. Please tell me that I am completely wrong?
source share