Advertisement
hocikto19

Quick Sort

Mar 12th, 2014
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. void quickSort(int arr[], int from, int to){
  2.     int i = from, j = to, pivot = arr[from], pom;
  3.     if (to - from>0){
  4.         while (i < j){
  5.             while (arr[i] <= pivot)
  6.                 i++;
  7.             while (arr[j] > pivot)
  8.                 j--;
  9.             if (i < j){
  10.                 pom = arr[i];
  11.                 arr[i] = arr[j];
  12.                 arr[j] = pom;
  13.             }
  14.         }
  15.         pom = arr[from];
  16.         arr[from] = arr[j];
  17.         arr[j] = pom;
  18.         quickSort(arr, from, j - 1);
  19.         quickSort(arr, i, to);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement