SamuelManik

Untitled

Mar 20th, 2018
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #define n 11
  3. using namespace std;
  4.  
  5. int A[n] = {25,12,37,15,20,45,34,3,29,7,32};
  6.  
  7. void sort(int l, int r);
  8.  
  9. main()
  10. {
  11.     int i ,kiri,kanan,kali,X;
  12.     cout<<"Sebelum di Sort\n";
  13.     for(i=0; i<=n-1; i++)
  14.         cout<<A[i]<<" ";
  15.     cout<<endl;
  16.  
  17.     sort(0, n-1);
  18.    
  19.     cout<<"\nSetelah di Sort\n";
  20.     for(i=0; i<=n-1; i++)
  21.         cout<<A[i]<<" ";
  22.     cout<<endl;
  23.     system("pause");
  24. }
  25.    
  26.     void sort(int kiri,int kanan)
  27. {
  28.     int i,ii,j,x,pivot,w,k;
  29.     i=kiri;
  30.     j=kanan;
  31.     pivot=A[i];
  32.     //pivot = A[i + (rand() % (j-i + 1))];
  33.     while (i <= j)
  34. }
  35.     {
  36.         while(A[i] < pivot)
  37.         i++;
  38.         while(pivot < A[j])
  39.         j--;
  40.         if(i <= j)
  41.         {
  42.         swap(A[i],A[j]);
  43.         i++;
  44.         j--;
  45.         }
  46.    
  47.     if(kiri<j)
  48.         sort(kiri,j);
  49.     if(i<kanan)
  50.         sort(i,kanan);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment