Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 16th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void SortingThread::quickSort(QList<int> numbers, int left, int right)
  2. {
  3.     int i = left, j = right;
  4.     int pivot = numbers[(left + right) / 2];
  5.  
  6.     // partition
  7.     while( i <= j )
  8.     {
  9.         while( numbers[i] < pivot )
  10.             i++;
  11.  
  12.         while( numbers[j] > pivot )
  13.             j--;
  14.  
  15.         if( i <= j )
  16.         {
  17.             swap(numbers, i, j);
  18.  
  19.             i++;
  20.             j--;
  21.         }
  22.     }
  23.  
  24.     // recursion
  25.     if( left < j )
  26.         quickSort(numbers, left, j);
  27.  
  28.     if( i < right )
  29.         quickSort(numbers, i, right);
  30. }