quicksort

Run Settings
LanguagePython
Language Version
Run Command
items = [23, 15, 29, 11, 44, 39, 56, 48, 52, 78, 87, 62, 50] def quicksort(dataset, first, last): if first < last: pivotIdx = partition(dataset, first, last) quicksort(dataset, first, pivotIdx -1) quicksort(dataset, pivotIdx + 1, last) def partition(data, first, last): pivotvalue = data[first] lower = first + 1 upper = last done = False while not done: while lower <= upper and data[lower] <= pivotvalue: lower += 1 while upper >= lower and data[upper] >= pivotvalue: upper -= 1 if upper < lower: done = True else: temp = data[lower] data[lower] = data[upper] data[upper] = temp temp = data[first] data[first] = data[upper] data[upper] = temp return upper print(items) quicksort(items, 0, len(items) - 1) print(items)
Editor Settings
Theme
Key bindings
Full width
Lines