You are viewing a single comment's thread. Return to all comments →
public static List<Integer> quickSort(List<Integer> arr) { List<Integer> left = new ArrayList<>(); List<Integer> equal = new ArrayList<>(); List<Integer> right = new ArrayList<>(); int p = arr.get(0); for(int i = 0; i < arr.size(); i++) { int element = arr.get(i); if(element < p) { left.add(element); } else if (element > p) { right.add(element); } else { equal.add(element); } } left.addAll(equal); left.addAll(right); return left; }
Seems like cookies are disabled on this browser, please enable them to open this website
Quicksort 1 - Partition
You are viewing a single comment's thread. Return to all comments →