Advertisement
meta1211

Untitled

Oct 29th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. void Array::BitSort(int *a, int n, int start, int end, int cmpByte)
  2. {
  3.     int i = start;
  4.     int j = end;
  5.     if (i < j)
  6.     {
  7.         int mask = 1 << cmpByte;
  8.         while (i <= j)
  9.         {
  10.             for (; i <= j && !(a[i] & mask); i++);
  11.             for (; i <= j && (a[j] & mask); j--);
  12.             if (i < j)
  13.             {
  14.                 Swap(&a[i], &a[j]);
  15.                 i++;
  16.                 j--;
  17.             }
  18.         }
  19.         if (start < j)
  20.         {
  21.             BitSort(a, n, start, j, cmpByte - 1);
  22.         }
  23.         if (i < end)
  24.         {
  25.             BitSort(a, n, i, end, cmpByte - 1);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement