diff --git a/stooge_sort.py b/stooge_sort.py index 55fd136..0723d2c 100644 --- a/stooge_sort.py +++ b/stooge_sort.py @@ -1,33 +1,32 @@ -# Python program to implement stooge sort - +Python program to implement stooge sort def stoogesort(arr, l, h): if l >= h: return - # If first element is smaller - # than last, swap them + If first element is smaller + than last, swap them if arr[l]>arr[h]: t = arr[l] arr[l] = arr[h] arr[h] = t - # If there are more than 2 elements in - # the array + If there are more than 2 elements in + the array if h-l + 1 > 2: t = (int)((h-l + 1)/3) - # Recursively sort first 2 / 3 elements + Recursively sort first 2 / 3 elements stoogesort(arr, l, (h-t)) - # Recursively sort last 2 / 3 elements + Recursively sort last 2 / 3 elements stoogesort(arr, l + t, (h)) - # Recursively sort first 2 / 3 elements - # again to confirm + Recursively sort first 2 / 3 elements + again to confirm stoogesort(arr, l, (h-t)) -# deriver +deriver arr = [2, 4, 5, 3, 1] n = len(arr)