Advertisement
Guest User

Untitled

a guest
May 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. // make quicksort instead
  2.     // quicksort function that chooses the last value as pivot
  3.     private LinkedList<Vertice> quickSortOfVertice(LinkedList<Vertice> list, int low, int high) {
  4.  
  5.         if(low < high) {
  6.            
  7.             int k = partitioning(list,low,high);
  8.            
  9.         list = quickSortOfVertice(list,low,k-1);
  10.         list = quickSortOfVertice(list,k+1,high);
  11.            
  12.         }
  13.  
  14.         return list;
  15.  
  16.     }
  17.  
  18.     private int partitioning(LinkedList<Vertice> list, int low, int high) {
  19.  
  20.         int pivot = list.get(list.lastIndexOf(list)).getDistance();
  21.         int i = (low - 1);
  22.         for (int j = low; j < high; j++) {
  23.  
  24.             if (list.get(j).getDistance() <= pivot) {
  25.                 i++;
  26.  
  27.                 Vertice temp = list.get(i);
  28.                 list.set(i, list.get(j));
  29.                 list.set(j, temp);
  30.             }
  31.         }
  32.  
  33.         Vertice temp2 = list.get(i+1);
  34.         list.set(i+1,list.get(high));
  35.         list.set(high,temp2);
  36.        
  37.    
  38.         return i+1; //since i is initally declared as the lowest index -1  
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement