Created
May 6, 2016 20:52
-
-
Save jsutch/8ad63ea634fb2be359c22c12645226f7 to your computer and use it in GitHub Desktop.
bubble sort
This file contains 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
#!/usr/local/bin/python | |
import random | |
import time | |
# add time delta | |
#Bubble sort list | |
group2 = [3,2,1,9,7,9,5,1] | |
group3 = [9,8,7,6,5,4,3,2,1] | |
group1 = [] | |
for x in range(1,1000): | |
group1.append(random.randrange(1,10000)) | |
x += 1 | |
print "Group Start:" | |
print time.time() | |
start = time.time() | |
print group1 | |
for loop in range(0,len(group1)): | |
# print "Loop", loop | |
# print group1 | |
for x in range(0,len(group1) -1): | |
# while x < range(0,len(group1)): | |
# print "Iteration",x, "Current Item",group1[x], "Item Neighbor",group1[x + 1] | |
if x == 8: | |
break | |
if group1[x] >= group1[x + 1]: | |
temp = group1[x + 1] | |
group1[x + 1] = group1[x] | |
group1[x] = temp | |
x += 1 | |
# else: | |
# print "no match" | |
# print group1 | |
loop += 1 | |
end = time.time() | |
print group1 | |
print "Group COMPLETE! - run took", (end - start), " seconds" | |
#first attempt | |
# while x < len(group1) -1: | |
# print x | |
# if group1[x] > group1[x + 1]: | |
# group1[x], group1[x + 1] = group1[x + 1], group1[x] | |
# x += 1 | |
# print group1 | |
# else: | |
# x += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment