@fitzcn/

LawfulPowerlessBrownbutterfly

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#http://interactivepython.org/runestone/static/pythonds/SortSearch/TheBubbleSort.html
def bubbleSort(items):
	#setup number of passes through the list
	for passnum in range(len(items)-1,0,-1):
		#setup each comparison within a given pass
		for i in range(passnum):
			print(items)
			#compare items
			if items[i]>items[i+1]:
				#swap items if necessary
				print("swapping " + str(items[i]) + " with " + str(items[i+1]))
				temp = items[i]
				items[i] = items[i+1]
				items[i+1] = temp
				
#initialize a list of something, sort it, and print it
numbers = [54,26,93,17,77,31,44,55,20]
bubbleSort(numbers)
print(numbers)

"""
PSEUDO CODE
starting with i = 0, take nth and (i+1)th items in the list (i.e. first and second to start)
	compare items with each other
		swap order if necessary
	move on to the next two items (n+1 and n+2) and repeat above until pass through whole list
start over again and pass through the list as many times as there are items in the list
"""