コード例 #1
0
def searchData(unsortedList, sortedList):
    """
    This function runs the two searching algorithms and tracks there data.
    Input: Sorted and unsorted list
    Output: text file of data
    """
    # Begin by testing the binary search
    binarySearchData = []
    linearSearchData = []

    # the range of testing the list begins at zero
    testRange = 0

    # get a value that is known not to be in the list
    target = 0
    while target in sortedList:
        target += 1

    for i in range(len(sortedList) + 1):
        binarySearchCount = Searches.binarySearch(sortedList[:testRange],
                                                  target)
        binarySearchData.append(binarySearchCount[1])

        linearSearchCount = Searches.linearSearch(sortedList[:testRange],
                                                  target)
        linearSearchData.append(linearSearchCount[1])

        testRange += 1

    # Wrtie the search data to text file
    writeSearchDataToText(binarySearchData, linearSearchData)