Give me a python implementation of quicksort
- User
Give me a python implementation of quicksort
Assistant
The python code for quicksort is as follows:
def quicksort(sequence): if len(sequence) > 1: p = partition(sequence, 1, len(sequence)) quicksort(sequence[:p]) quicksort(sequence[p+1:]) return sequence
function partition(sequence, start, end) pivot = sequence[start] i = start j = end - 1 while i < j: while sequence[i] < pivot: i += 1 while sequence[j] > pivot: j -= 1 if i < j: sequence[i], sequence[j] = sequence[j], sequence[i] i += 1 j -= 1 return i
Implementation of a Quicksort in python
- User
Now, make the same algorithm in Haskell
Assistant
The haskell code for quicksort is as follows:
quicksort [] = [] quicksort (p:ps) = qs ++ [x] ++ qs' where (qs, qs') = splitAt 1 ps x = p
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.