Skip to content

Instantly share code, notes, and snippets.

@mauriciogardini
Created August 15, 2019 03:17
Show Gist options
  • Save mauriciogardini/ad3d4b683dc253494c385dbe745aa858 to your computer and use it in GitHub Desktop.
Save mauriciogardini/ad3d4b683dc253494c385dbe745aa858 to your computer and use it in GitHub Desktop.
Bubble Sort implementation in Python
def bubble_sort(array, decrescent=False):
if len(array) <= 1:
return array
for x in range(len(array) - 1):
for y in range(len(array) - x - 1):
if ((decrescent and array[y] < array[y + 1]) or
(not decrescent and array[y] > array[y + 1])):
array[y], array[y + 1] = array[y + 1], array[y]
return array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment