MCPcopy Create free account
hub / github.com/geekcomputers/Python / stooge_sort_

Function stooge_sort_

Sorting Algorithms/stooge_sort.py:5–27  ·  view source on GitHub ↗
(arr, l, h)

Source from the content-addressed store, hash-verified

3
4
5def stooge_sort_(arr, l, h):
6 if l >= h:
7 return 0
8
9 # If first element is smaller than last, then swap
10
11 if arr[l] > arr[h]:
12 t = arr[l]
13 arr[l] = arr[h]
14 arr[h] = t
15
16 # If there are more than 2 elements in array
17 if h - l + 1 > 2:
18 t = (int)((h - l + 1) / 3)
19
20 # Recursively sort first 2 / 3 elements
21 stooge_sort_(arr, l, (h - t))
22
23 # Recursively sort last 2 / 3 elements
24 stooge_sort_(arr, l + t, (h))
25
26 # Recursively sort first 2 / 3 elements
27 stooge_sort_(arr, l, (h - t))
28
29
30arr = [2, 4, 5, 3, 1]

Callers 1

stooge_sort.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected