Solve a problem – Filter by language, license, keyword, owner, or search text to find code & info fast.
Updated over 8 years ago (28 Jun 2008 at 03:16 AM) recent activity
|In Brief||A simple implementation of the Bubble Sort algorithm.... more|
3 swapped = True
5 # Keep making passes unless nothing is changed for an entire pass
6 while swapped == True:
8 swapped = False
10 # Step over array
11 for i in xrange(len(array) - 1):
13 if array[i] > array[i+1]:
14 array[i], array[i+1] = array[i+1], array[i] #That's right I just used a tuple to swap things
15 # Mark as changed
16 swapped = True
18 return array
A simple implementation of the Bubble Sort algorithm.
Pass it a list or anything indexable in Python and it will reorder it in place and pass it back.