Created
January 30, 2013 13:43
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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