FUCK THE POLICE
911 EVERY DAY
Haskell:
C++:
Code:
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
C++:
Code:
void quicksort(int a[], int left, int right)
{
if (left < right)
{
int pivot = partition(a, left, right);
quicksort(a, left, pivot-1);
quicksort(a, pivot+1, right);
}
}
int partition(int a[], int left, int right)
{
int pivot = a[left];
while (true)
{
while (a[left] < pivot) left++;
while (a[right] > pivot) right--;
if (left < right)
{
swap(a[left], a[right]);
}
else
{
return right;
}
}
}