You are viewing a single comment's thread. Return to all comments →
Hi,
I have used this logic.
static void countSwaps(int[] a) { int arrLength = a.length; int temp; int count = 0; for(int i=0;i a[j+1]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; flag = 1; count++; } } if(flag == 0) { break; } } System.out.println("Array is sorted in "+count+" swaps."); System.out.println("First Element: "+a[0]); System.out.println("Last Element: "+a[arrLength-1]); }
Here, I am getting count as "0" in hackerrank output. But, when I am testing in my local machine, I am getting actual number of swaps(more than 0).
Why it is happening like that?
Sorting: Bubble Sort
You are viewing a single comment's thread. Return to all comments →
Hi,
I have used this logic.
Why it is happening like that?