You are viewing a single comment's thread. Return to all comments →
public static int runningTime(List<Integer> arr) { int n = arr.size(); int swaps = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < n - i - 1; j++) { Integer e1 = arr.get(j); Integer e2 = arr.get(j + 1); if(e1 > e2) { //swap arr.set(j, e2); arr.set(j + 1, e1); swaps++; } } } return swaps; }
Seems like cookies are disabled on this browser, please enable them to open this website
Running Time of Algorithms
You are viewing a single comment's thread. Return to all comments →