Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // make quicksort instead
- // quicksort function that chooses the last value as pivot
- private LinkedList<Vertice> quickSortOfVertice(LinkedList<Vertice> list, int low, int high) {
- if(low < high) {
- int k = partitioning(list,low,high);
- list = quickSortOfVertice(list,low,k-1);
- list = quickSortOfVertice(list,k+1,high);
- }
- return list;
- }
- private int partitioning(LinkedList<Vertice> list, int low, int high) {
- int pivot = list.get(list.lastIndexOf(list)).getDistance();
- int i = (low - 1);
- for (int j = low; j < high; j++) {
- if (list.get(j).getDistance() <= pivot) {
- i++;
- Vertice temp = list.get(i);
- list.set(i, list.get(j));
- list.set(j, temp);
- }
- }
- Vertice temp2 = list.get(i+1);
- list.set(i+1,list.get(high));
- list.set(high,temp2);
- return i+1; //since i is initally declared as the lowest index -1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement