Skip to content

Instantly share code, notes, and snippets.

@pieterjd
Created January 30, 2013 13:43
Show Gist options
  • Select an option

  • Save pieterjd/4673400 to your computer and use it in GitHub Desktop.

Select an option

Save pieterjd/4673400 to your computer and use it in GitHub Desktop.
Bubblesort in Python Contains smart way to create an array with random integers
import random
def bubblesort(a):
i = len(a)
while i!=0:
j = 0
while j!=i-1:
#print 'index j:',j
if(a[j+1]<a[j]):
temp = a[j+1]
a[j+1] =a[j]
a[j]=temp
j+=1
i-=1
#create array with random values
a=random.sample(range(0,10),10)
bubblesort(a)
a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment