You are viewing a single comment's thread. Return to all comments →
int numberOfSwaps = 0; for(int i = 0; i< n; i++){ for(int j =0; j < n-1; j++){ if(a.get(j)> a.get(j+1)){ int temp = a.get(j); a.set(j, a.get(j+1)); a.set(j+1, temp); numberOfSwaps++; } } } System.out.println("Array is sorted in "+ numberOfSwaps+ " swaps."); System.out.println("First Element: "+ a.get(0)); System.out.println("Last Element: "+ a.get(n-1));
}
Seems like cookies are disabled on this browser, please enable them to open this website
Day 20: Sorting
You are viewing a single comment's thread. Return to all comments →
}