Advertisement
sonprao

QUICKSORT

Sep 16th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1. void sort(int *a,int l, int r)
  2. {
  3.     int i,j,x,y;
  4.     i=l;
  5.     j=r;
  6.     x=a[(l+r)/2];
  7.     while (i<=j)
  8.     {
  9.         while (a[i]<x) i++;
  10.         while (x<a[i]) j--;
  11.         if (i<=j)
  12.         {
  13.             y=a[i];
  14.             a[i]=a[j];
  15.             a[j]=y;
  16.             i++;
  17.             j--;
  18.         }
  19.     }
  20.     if (l<j) sort(l,j);
  21.     if (i<r) sort(i,r);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement