def test_sort(enabled): if enabled: if SORT_BUBBLE_ENABLED: # Bubble algorithm reset("Bubble Sort") sort.bubble(input) if SORT_INSERT_ENABLED: # Insert algorithm reset("Insertion Sort") sort.insert(input) if SORT_MERGE_ENABLED: # Merge algorithm reset("Merge Sort") sort.merge(input) if SORT_QUICK_ENABLED: # QuickSOrt algorithm reset("Quick Sort") sort.quick(input)
#! /usr/bin/env python # coding=utf-8 from sort import bubble import time a = [i for i in xrange(10000)] bubble(a) def timing(f, *args, **kwargs): def deco(*args, **kwargs): b = time.time() r = f(*args, **kwargs) e = time.time() print "{} seconds".format(e - b) return r return deco @timing def bi_search(a, key, low, high): if low < high and low >= 0: mid = (high - low + 1)/2 print "low = %d, high = %d, mid = %d" % (low, high, mid) d = key - a[mid] if d == 0: return True elif d < 0: return bi_search(a, key, low, mid) else: return bi_search(a, key, mid, high)
def test_bubble(arr): assert sort.bubble(arr) == sorted(arr)
from sort import bubble list_a = [233, 1, 453, 35, 87, 400, 46, 77, 35, 700] print(list_a) bubble(list_a) # length = len(list_a) # for times in range(1, length): # for flag in range(1, length-times+1): # if list_a[flag-1] > list_a[flag]: # list_a[flag-1], list_a[flag] = list_a[flag], list_a[flag-1] print(list_a)
import sort print ["Adam", "Henry", "Alex", "Jerry", "Zim", "Paul", "Travis"] print sort.bubble(["Adam", "Henry", "Alex", "Jerry", "Zim", "Paul", "Travis"]) print [10,5,7,8,2,1,4,34,0,9] print sort.bubble([10,5,7,8,2,1,4,34,0,9]) print sort.bubble([10,5,7,8,2,1,4,34,0,9], 'rev') print sort.seq_search('cheese', ['a','b','c','d','cheese'])
def on_update(self, delta_time): bubble(self.bars)
def testbubble(self): self.assertEqual(bubble([1,5,2,3,5,7]),[1,2,3,5,5,7],'pass') self.assertEqual(selection([1,5,2,3,5,7]),[1,2,3,5,5,7],'pass')
def test_bubble(): a = random_array() expected = sorted(a) sort.bubble(a) s = 'bubble failed ({})'.format(a) assert str(expected) == str(a), s
for i in lstfib: print i if menuChoice == 2: for i in lstfib: if i % 2 == 0: # because even numbers are all divisible by 2. print i if menuChoice == 3: c = 0 while c < len(lstfib): if lstfib[c] % 2 != 0: retval = lstfib.pop(c) # for some reason pop doesn't actually pop. print retval else: print lstfib[c], "is an even number." c += 1 if menuChoice == 4: print lstfib lstfib = sort.bubble(lstfib, False, "rev") print lstfib if menuChoice == 5: ans = 0 for i in lstfib: ans += i print ans if menuChoice == 6: for i in lstfib: if i > 999: print i if menuChoice == 7: break
def testbubble(self): self.assertEqual(bubble([1, 5, 2, 3, 5, 7]), [1, 2, 3, 5, 5, 7], 'pass') self.assertEqual(selection([1, 5, 2, 3, 5, 7]), [1, 2, 3, 5, 5, 7], 'pass')