Example #1
0
def main():
    # Create test array
    testArray = [random.randint(1, 100) for _ in range(20)]
    # measure the elapsed time for the algorithm
    start = time.time()
    merged = sort.merge(testArray)
    end = time.time()
    # print merge sort results
    print "Merge Sort: completed in: " + str(end - start) + " seconds"
    print testArray
    print str(merged) + '\n'
    # measure the elapsed time for the quick sort algorithm
    start = time.time()
    quickly = sort.quick(testArray)
    end = time.time()
    # print quick sort results
    print "Quick Sort: completed in: " + str(end - start) + " seconds"
    print testArray
    print str(quickly) + '\n'
    start = time.time()
    heaped = sort.heap(testArray)
    end = time.time()
    # print merge sort results
    print "Heap Sort: completed in: " + str(end - start) + " seconds"
    print testArray
    print str(heaped) + '\n'
Example #2
0
def anagram_mergesort(l):
    def anagram_comp(a,b):
        return sorted(a)==sorted(b)
    if len(l)==1:
        return l
    middle = len(l)/2
    return sort.merge(
        anagram_mergesort(l[:middle]),
        anagram_mergesort(l[middle:]),
        anagram_comp)
Example #3
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)
Example #4
0
 def test_merge(self):
     list1 = [7, 5, 1, 8, 3, 4, 4, 7]
     list2 = [3, 6, 2, 1, 8, 9, 0, 6]
     list1 = sort.tree_sort(list1)
     list2 = sort.tree_sort(list2)
     assert sort.merge(list1=list1, list2=list2) == [0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 9]
Example #5
0
 def test_merge(self):
     self.assertEqual(sort.merge([3, 4, 2, 6, 6, 1]), [1, 2, 3, 4, 6, 6])
     self.assertEqual(len(sort.merge([3, 4, 2, 6, 6, 1])), 6)
Example #6
0
 def test_insertion(self):
     self.assertEqual(sort.merge(self.numbers), self.correct)
Example #7
0
def test_search():
    input = INPUT_ARRAY[:]
    sort.merge(input)

    search = Search(input)
    search.binarySearch(7)
Example #8
0
import ordsearch
import sort
import dup
import util

hacktest = util.words("hacktest.txt")
hacktest = sort.merge(hacktest)
unihacktest = dup.remove_dup(hacktest)
print("unique elements in sorted hacktest.txt: ",len(unihacktest))

print()

grail = util.words("grail.txt")
grail = sort.merge(grail)
unigrail = dup.remove_dup(grail)
print("unique elements in sorted grail.txt: ",len(unigrail))

print()

hacktest = util.words("hacktest.txt")
notunihacktest = dup.remove_dup(hacktest)
print("unique elements in unsorted hacktest.txt: ",len(notunihacktest))

print()

grail = util.words("grail.txt")
notunigrail = dup.remove_dup(grail)
print("unique elements in unsorted grail.txt: ",len(notunigrail))
Example #9
0
def merge(elements):
    return sort.merge(elements)
Example #10
0
__author__ = 'Egbert'

from sort import bubble
from sort import merge
from util import words
from ordsearch import binary

#print(bubble([3,253,223,52,6,23,6,2,6,8,3,5,34,8,3,433,76,83465,8,34,36,457,5478,3,45,2]))
#print(bubble(words("hacktest.txt")))
#print(bubble(words("Unabr.dict")))

#print(merge([3,253,223,52,6,23,6,2,6,8,3,5,34,8,3,433,76,83465,8,34,36,457,5478,3,45,2]))
#print(merge(words("hacktest.txt")))
#print(merge(words("Unabr.dict")))

print(binary(merge(words("grail.txt")),"swallow"))
Example #11
0
 def __add__(self, other):
     new_entries = sort.merge(self.entries, other.entries)
     return Bib.from_list(new_entries)