예제 #1
0
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)
예제 #2
0
파일: search.py 프로젝트: bluerwf/study
#! /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)
예제 #3
0
def test_bubble(arr):
    assert sort.bubble(arr) == sorted(arr)
예제 #4
0
파일: main.py 프로젝트: cielo33456/practice
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)
예제 #5
0
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'])
예제 #6
0
 def on_update(self, delta_time):
     bubble(self.bars)
예제 #7
0
파일: test.py 프로젝트: fndjjx/practice
 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')
예제 #8
0
def test_bubble():
    a = random_array()
    expected = sorted(a)
    sort.bubble(a)
    s = 'bubble failed ({})'.format(a)
    assert str(expected) == str(a), s
예제 #9
0
        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
예제 #10
0
파일: test.py 프로젝트: renewday/practice
 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')