Skip to content

Instantly share code, notes, and snippets.

@devansh42
Last active December 30, 2020 08:10
Show Gist options
  • Save devansh42/e62f2fc3515f164fd28549cead44380b to your computer and use it in GitHub Desktop.
Save devansh42/e62f2fc3515f164fd28549cead44380b to your computer and use it in GitHub Desktop.
def bubble_sort(ar):
if len(ar)<=1:
return ar
if len(ar)==2:
return ar if ar[0]<ar[1] else [ar[1],ar[0]]
a,b,bs=ar[0],ar[1],ar[2:]
res = []
if a<b:
res = [a] + bubble_sort([b]+bs)
else:
res = [b] + bubble_sort([a]+bs)
return bubble_sort(res[:-1]) + res[-1:]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment