Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #add to your bst
- def traverse(self):
- a = []
- self._traverse_aux(self._root, a)
- return a
- def _traverse_aux(self, node, a):
- if node is not None:
- self._traverse_aux(node._left, a)
- a.append(deepcopy(node._data))
- self._traverse_aux(node._right, a)
- return
- #data structures
- """
- -------------------------------------------------------
- sorts_array.py
- [description of functions]
- -------------------------------------------------------
- Author: Prayrit Khanna
- ID: 160596860
- Email: khan6860@mylaurier.ca
- __updated__ = "2017-03-20"
- -------------------------------------------------------
- """
- # Imports
- from math import log
- from bst_linked import BST
- class Sorts:
- """
- -------------------------------------------------------
- Defines a number of array-based sort operations.
- Uses class attribute 'swaps' to determine how many times
- elements are swapped by the class.
- Use: print(Sorts.swaps)
- Use: Sorts.swaps = 0
- -------------------------------------------------------
- """
- swaps = 0 # Tracks swaps performed.
- # The Sorts
- @staticmethod
- def selection_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Selection Sort algorithm.
- Use: Sorts.selection_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - a Python list of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- n = len(a)
- i = 0
- while i < n:
- # Walk through entire array
- m = i
- j = i + 1
- while j < n:
- # Find smallest value in unsorted part of array
- if a[m] > a[j]:
- # Track smallest value so far
- m = j
- j += 1
- if m != i:
- # swap elements only if necessary
- Sorts._swap(a, m, i)
- i = i + 1
- return
- @staticmethod
- def insertion_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Insertion Sort algorithm.
- Use: Sorts.insertion_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- n = len(a)
- i = 1
- while i < n:
- # Walk through entire array
- # Move each key bigger than save in a[1:n-1] one space to right.
- save = a[i]
- # Count as a swap
- Sorts.swaps += 1
- j = i - 1
- while j >= 0 and a[j] > save:
- Sorts._shift(a, j + 1, j)
- j -= 1
- # Move save into hole opened up by moving previous keys to right.
- a[j + 1] = save
- i += 1
- return
- @staticmethod
- def bubble_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Bubble Sort algorithm.
- Use: Sorts.bubble_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- done = False
- last = len(a) - 1
- while not done:
- # assume done is true
- done = True
- last_swapped = 0
- i = 0
- while i < last:
- if a[i] > a[i + 1]:
- # Save the list index swapped.
- last_swapped = i
- # The pair (a[i], a[i+1]) is out of order.
- # Exchange a[i] and a[i + 1] to put them in sorted order.
- Sorts._swap(a, i, i + 1)
- # If you swapped you need another pass.
- done = False
- i += 1
- last = last_swapped
- # Decreases 'last' because everything after last_swapped is already
- # in order. done == False iff no pair of keys swapped on last pass.
- return
- @staticmethod
- def bst_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Tree Sort algorithm.
- Use: Sorts.bst_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- bst = BST()
- for v in a:
- bst.insert(v)
- a[:] = bst.traverse()
- return
- @staticmethod
- def shell_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Shell Sort algorithm.
- Use: Sorts.shell_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- n = len(a)
- increment = n // 3
- while increment > 0:
- i = increment
- while i < n:
- j = i
- temp = a[i]
- while j >= increment and a[j - increment] > temp:
- Sorts._shift(a, j, j - increment)
- j = j - increment
- a[j] = temp
- i += 1
- increment = increment // 3
- return
- @staticmethod
- def merge_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Merge Sort algorithm.
- Use: Sorts.merge_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- Sorts._merge_sort_aux(a, 0, len(a) - 1)
- return
- @staticmethod
- def _merge_sort_aux(a, first, last):
- """
- -------------------------------------------------------
- Divides an array into halves, sorts each half, then
- merges the halves back together.
- Use: Sorts._merge_sort_aux(a, first, last)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- first - beginning of subarray of a (int)
- last - end of subarray of a (int)
- Postconditions:
- Contents of a from first to last are sorted.
- -------------------------------------------------------
- """
- if first < last:
- middle = (last - first) // 2 + first
- Sorts._merge_sort_aux(a, first, middle)
- Sorts._merge_sort_aux(a, middle + 1, last)
- Sorts._merge(a, first, middle, last)
- return
- @staticmethod
- def _merge(a, first, middle, last):
- """
- -------------------------------------------------------
- Merges two parts of an array together.
- Use: Sorts._merge(a, first, middle, last)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- first - beginning of subarray of a (int)
- middle - middle of subarray of a (int)
- last - end of subarray of a (int)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- temp = []
- i = first
- j = middle + 1
- while i <= middle and j <= last:
- if a[i] <= a[j]:
- # put leftmost element of left array into temp array
- temp.append(a[i])
- i += 1
- else:
- # put leftmost element of right array into temp array
- temp.append(a[j])
- j += 1
- # copy any remaining elements from the left half
- while i <= middle:
- temp.append(a[i])
- i += 1
- # copy any remaining elements from the right half
- while j <= last:
- temp.append(a[j])
- j += 1
- # copy the temporary array back to the passed array
- i = 0
- while i < len(temp):
- a[first + i] = temp[i]
- i += 1
- return
- @staticmethod
- def quick_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Quick Sort algorithm.
- Use: Sorts.quick_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- Sorts._quick_sort_aux(a, 0, len(a) - 1)
- return
- @staticmethod
- def _quick_sort_aux(a, first, last):
- """
- -------------------------------------------------------
- Divides an array into halves, sorts each half, then
- concatenates the halves back together.
- Use: Sorts._quick_sort_aux(a, first, last)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- first - beginning of subarray of a (int)
- last - end of subarray of a (int)
- Postconditions:
- Contents of a from first to last are sorted.
- -------------------------------------------------------
- """
- # to sort the subarray a[p:q] of array a into ascending order
- if first < last:
- # partitions a[first:last] into a[first:pivot] and a[pivot+1:last]
- i = Sorts._partition(a, first, last)
- Sorts._quick_sort_aux(a, first, i - 1)
- Sorts._quick_sort_aux(a, i + 1, last)
- return
- @staticmethod
- def _partition(a, first, last):
- """
- -------------------------------------------------------
- Divides an array into two parts.
- Use: Sorts._partition(a, first, last)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- first - beginning of subarray of a (int)
- last - last of subarray of a (int)
- Postconditions:
- Contents of a from first to last are sorted.
- -------------------------------------------------------
- """
- pivot_index = first
- low = first
- high = last - 1 # After we remove pivot it will be one smaller
- # print("{} - {} - {}".format(a[first:pivot_index], a[pivot_index],
- # a[pivot_index + 1:last]))
- pivot_value = a[pivot_index]
- a[pivot_index] = a[last]
- while low <= high:
- # print("{} - {} - {}".format(a[first:pivot_index],
- # a[pivot_index], a[pivot_index + 1:last]))
- while low <= high and a[low] < pivot_value:
- low = low + 1
- while low <= high and a[high] >= pivot_value:
- high = high - 1
- if low <= high:
- Sorts._swap(a, low, high)
- Sorts._shift(a, last, low)
- # a[last] = a[low]
- a[low] = pivot_value
- # print("{} - {} - {}".format(a[first:pivot_index], a[pivot_index],
- # a[pivot_index + 1:last]))
- # Return the new pivot position.
- return low
- @staticmethod
- def heap_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Heap Sort algorithm.
- Use: Sorts.heap_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- first = 0
- last = len(a) - 1
- Sorts._build_heap(a, first, last)
- i = last
- while i > first:
- Sorts._swap(a, i, first)
- Sorts._reheap(a, first, i - 1)
- i -= 1
- return
- @staticmethod
- def _build_heap(a, first, last):
- """
- -------------------------------------------------------
- Creates a heap.
- Use: Sorts._build_heap(a, first, last)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (list)
- first - first element in array to process (int)
- last - last element in array to process (int)
- Postconditions:
- Contents of a from first to last are sorted.
- -------------------------------------------------------
- """
- i = last // 2
- while i >= first:
- Sorts._reheap(a, i, last)
- i -= 1
- return
- @staticmethod
- def _reheap(a, first, last):
- """
- -------------------------------------------------------
- Establishes heap property in a.
- Use: Sorts._reheap(a, first, last)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- first - first element in array to process (int)
- last - last element in array to process (int)
- Postconditions:
- Contents of a from first to last are heaped.
- -------------------------------------------------------
- """
- done = False
- while 2 * first + 1 <= last and not done:
- k = 2 * first + 1
- if k < last and a[k] < a[k + 1]:
- k += 1
- if a[first] >= a[k]:
- done = True
- else:
- Sorts._swap(a, first, k)
- first = k
- return
- @staticmethod
- def comb_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Comb Sort algorithm.
- Use: Sorts.comb_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- n = len(a)
- gap = n
- done = False
- while gap > 1 or not done:
- done = True
- gap = int(gap / 1.3)
- if gap < 1:
- gap = 1
- i = 0
- j = gap
- while j < n:
- if a[i] > a[j]:
- Sorts._swap(a, i, j)
- done = False
- i += 1
- j += 1
- return
- @staticmethod
- def cocktail_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Cocktail Sort algorithm.
- Use: Sorts.cocktail_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- n = len(a)
- first = 0
- last = n - 1
- while first < last:
- # Initialize last_swapped to the beginning of the array.
- # Stops bottom loop from executing if no swaps done by top loop.
- last_swapped = 0
- i = first
- while i < last:
- if a[i] > a[i + 1]:
- # test whether the two elements are in the correct order
- Sorts._swap(a, i, i + 1)
- last_swapped = i
- i += 1
- last = last_swapped
- # Initialize first_swapped to the end of the array.
- # Stops top loop from executing if no swaps done by bottom loop.
- first_swapped = n - 1
- i = last
- while i > first:
- if a[i] < a[i - 1]:
- # test whether the two elements are in the correct order
- Sorts._swap(a, i, i - 1)
- first_swapped = i
- i -= 1
- first = first_swapped
- return
- @staticmethod
- def binary_insert_sort(a):
- """
- -------------------------------------------------------
- Sorts an array using the Binary Insertion Sort algorithm.
- Use: Sorts.binary_insert_sort(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (list)
- Postconditions:
- Contents of a are sorted.
- -------------------------------------------------------
- """
- n = len(a)
- i = 1
- while i < n:
- ins = Sorts._bin_srch_i(a, 0, i, a[i])
- # Move key bigger than save in a[1:n-1] one space to the right.
- if ins < i:
- save = a[i]
- j = i - 1
- while j > ins - 1:
- Sorts._shift(a, j + 1, j)
- # a[j + 1] = a[j]
- j -= 1
- a[ins] = save
- i += 1
- return
- @staticmethod
- def _bin_srch_r(a, low, high, value):
- """
- -------------------------------------------------------
- Sorts an array using the Binary Insertion Sort algorithm.
- Use: Sorts._bin_srch_r(a)
- Recursive algorithm.
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (list)
- low - starting point of a to search for value (int)
- high - end point of a to search for value (int)
- value - value to search for position in a (?)
- Postconditions:
- returns
- mid - the insert point for value in a between low and high
- -------------------------------------------------------
- """
- if low == high:
- mid = low
- else:
- mid = low + ((high - low) // 2)
- if value > a[mid]:
- mid = Sorts._bin_srch_r(a, mid + 1, high, value)
- elif value < a[mid]:
- mid = Sorts._bin_srch_r(a, low, mid, value)
- return mid
- @staticmethod
- def _bin_srch_i(a, low, high, value):
- """
- -------------------------------------------------------
- Sorts an array using the Binary Insertion Sort algorithm.
- Use: Sorts._bin_srch_r(a)
- Iterative algorithm.
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (list)
- low - starting point of a to search for value (int)
- high - end point of a to search for value (int)
- value - value to search for position in a (?)
- Postconditions:
- returns
- mid - the insert point for value in a between low and high
- -------------------------------------------------------
- """
- found = False
- mid = (low + high) // 2
- while low < high and not found:
- # Find the middle of the current subarray.
- if value > a[mid]:
- # Search the right subarray.
- low = mid + 1
- mid = (low + high) // 2
- elif value < a[mid]:
- # Search the left subarray.
- high = mid
- mid = (low + high) // 2
- else:
- found = True
- return mid
- # Sort Utilities
- @staticmethod
- def sort_test(a):
- """
- -------------------------------------------------------
- Determines whether an array is is_sorted or not.
- Use: sort_test(a)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- Postconditions:
- returns
- is_sorted - True if contents of a are sorted,
- False otherwise.
- -------------------------------------------------------
- """
- is_sorted = True
- n = len(a)
- i = 0
- while is_sorted and i < n - 1:
- if a[i] <= a[i + 1]:
- i += 1
- else:
- is_sorted = False
- return is_sorted
- @staticmethod
- def _swap(a, i, j):
- """
- -------------------------------------------------------
- Swaps the data contents of two array elements.
- Updates 'swaps'.
- Use: Sorts._swap(a, i, j)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- i - index of one value (int 0 <= i < len(a))
- j - index of another value (int 0 <= j < len(a))
- Postconditions:
- Values in a[i] and a[j] are swapped.
- -------------------------------------------------------
- """
- Sorts.swaps += 1
- temp = a[i]
- a[i] = a[j]
- a[j] = temp
- return
- @staticmethod
- def _shift(a, i, j):
- """
- -------------------------------------------------------
- Shifts the contents of a[j] to a[i].
- Updates 'swaps' - worth 1/3 of _swap
- Use: Sorts._shift(a, i, j)
- -------------------------------------------------------
- Preconditions:
- a - an array of comparable elements (?)
- i - index of one value (int 0 <= i < len(a))
- j - index of another value (int 0 <= j < len(a))
- Postconditions:
- Value in a[j] is copied to a[i].
- -------------------------------------------------------
- """
- Sorts.swaps += 0.34
- a[i] = a[j]
- return
- #DATA STRUCTURES
- """
- -------------------------------------------------------
- [file name]
- [program description]
- -------------------------------------------------------
- Author: Prayrit Khanna
- ID: 160596860
- Email: khan6860@mylaurier.ca
- __updated__ = "2017-03-20"
- -------------------------------------------------------
- """
- class Number:
- """
- -------------------------------------------------------
- Wraps a class definition around integers.
- Uses class attribute 'comparisons' to determine how many times
- comparison functions are called on the class.
- Use: print(Number.comparisons)
- Use: Number.comparisons = 0
- -------------------------------------------------------
- """
- comparisons = 0
- def __init__(self, data):
- """
- -------------------------------------------------------
- Creates a Number object.
- -------------------------------------------------------
- Preconditions:
- data - an integer (int)
- Postconditions:
- A Number object containing data is initialized.
- -------------------------------------------------------
- """
- self.data = data
- return
- def __str__(self):
- """
- -------------------------------------------------------
- Creates a formatted string of Number data.
- -------------------------------------------------------
- Postconditions:
- returns:
- the formatted contents of data (str)
- -------------------------------------------------------
- """
- return str(self.data)
- def __eq__(self, rs):
- """
- -------------------------------------------------------
- Compares this Number against another Number for equality.
- Use: n1 == n2
- -------------------------------------------------------
- Preconditions:
- rs - [right hand side] Number to compare to (Number)
- Postconditions:
- returns:
- result - True if data matches, False otherwise (boolean)
- -------------------------------------------------------
- """
- Number.comparisons += 1
- result = self.data == rs.data
- return result
- def __lt__(self, rs):
- """
- -------------------------------------------------------
- Determines if this Number comes before another.
- Use: n1 < n2
- -------------------------------------------------------
- Preconditions:
- rs - [right hand side] Number to compare to (Number)
- Postconditions:
- returns:
- result - True if this Number precedes rs,
- False otherwise (boolean)
- -------------------------------------------------------
- """
- Number.comparisons += 1
- result = self.data < rs.data
- return result
- def __le__(self, rs):
- """
- -------------------------------------------------------
- Determines if this Number precedes or is or equal to another.
- Use: n1 <= n2
- -------------------------------------------------------
- Preconditions:
- rs - [right hand side] Number to compare to (movie)
- Postconditions:
- returns:
- result - True if this Number precedes or is equal to rs,
- False otherwise (boolean)
- -------------------------------------------------------
- """
- Number.comparisons += 1
- result = self.data <= rs.data
- return result
- #Lab_10
- """
- -------------------------------------------------------
- [file name]
- [program description]
- -------------------------------------------------------
- Author: Prayrit Khanna
- ID: 160596860
- Email: khan6860@mylaurier.ca
- __updated__ = "2017-03-20"
- -------------------------------------------------------
- """
- # Imports
- import random
- from number import Number
- from sorts_array import Sorts
- from random import randint
- from copy import deepcopy
- # Constants
- SIZE = 100 # Size of array to sort.
- XRANGE = 1000 # Range of values in random arrays to sort.
- TESTS = 100 # Number of random arrays to generate.
- SORTS = (
- ('Bubble Sort', Sorts.bubble_sort),
- ('Insertion Sort', Sorts.insertion_sort),
- ('Merge Sort', Sorts.merge_sort),
- ('Quick Sort', Sorts.quick_sort),
- ('Selection Sort', Sorts.selection_sort),
- ('Bin. Ins. Sort', Sorts.binary_insert_sort),
- ('BST Sort', Sorts.bst_sort),
- ('Cocktail Sort', Sorts.cocktail_sort),
- ('Comb Sort', Sorts.comb_sort),
- ('Heap Sort', Sorts.heap_sort),
- ('Shell Sort', Sorts.shell_sort)
- )
- def create_sorted():
- """
- -------------------------------------------------------
- Create a sorted list of Number objects.
- -------------------------------------------------------
- Postconditions:
- returns
- values - a sorted list of SIZE Number objects.
- -------------------------------------------------------
- """
- values = []
- i = 0
- while i< SIZE:
- values.append(Number(i)) #turns i into an object rather than an integer
- i += 1
- return values
- def create_reversed():
- """
- -------------------------------------------------------
- Create a reversed list of Number objects.
- -------------------------------------------------------
- Postconditions:
- returns
- values - a reversed list of SIZE Number objects.
- -------------------------------------------------------
- """
- values = []
- i = SIZE
- while i>0:
- values.append(Number(i)) #turns i into an object rather than an integer
- i -= 1
- return values
- def create_randoms():
- """
- -------------------------------------------------------
- Create a 2D list of Number objects.
- -------------------------------------------------------
- Postconditions:
- returns
- arrays - TEST lists of SIZE Number objects containing
- values between 0 and XRANGE.
- -------------------------------------------------------
- """
- arrays = []
- i = 0
- while i<TESTS: #we are using TESTS lists, to get average of comparisons
- value = []
- x = 0
- while x<SIZE: #Generate random numbers for the smaller lists
- value.append(Number(randint(0,100)))
- x += 1
- arrays.append(value) #adding the smaller lists in the giant list
- i +=1
- return arrays
- def test_sort(title, func):
- """
- -------------------------------------------------------
- Test a sort function with Number data and print out
- its comparisons for sorted, reversed, and random arrays
- of data.
- -------------------------------------------------------
- Preconditions:
- title - name of the sorting function to call (str)
- func - the actual sorting function to call (function)
- Postconditions:
- prints the number of comparisons necessary to sort an
- array: in order, in reverse order, and a list of arrays
- in random order.
- -------------------------------------------------------
- """
- Number.comparisons = 0 #reset values
- Sorts.swaps = 0 #reset values
- #Ordered list
- order = create_sorted() #this creates a sorted list
- func(deepcopy(order)) #function takes the parameter of the list, not 2D list, or numbers.
- ordered_comparison = Number.comparisons
- ordered_swaps = Sorts.swaps
- #print("order:",Sorts.swaps)
- Number.comparisons = 0 #reset values
- Sorts.swaps = 0 #reset values
- #print("order cleaned:",Sorts.swaps)
- #reversed list
- reverse = create_reversed()
- func(deepcopy(reverse))
- reversed_comparison = Number.comparisons
- reversed_swaps = Sorts.swaps
- #print(Sorts.swaps)
- Number.comparisons = 0 #reset values
- Sorts.swaps = 0 #reset values
- #print(Sorts.swaps)
- #Random list
- rand = create_randoms()
- i = 0
- while i<len(rand):
- func(rand[i])
- i += 1
- random_comparison = Number.comparisons//100
- random_swap = Sorts.swaps//100
- print ("{:<14} {:>8.0f} {:>8.0f} {:>8.0f} {:>8.0f} {:>8.0f} {:>8.0f}".format(title, ordered_comparison, reversed_comparison, random_comparison, ordered_swaps, reversed_swaps, random_swap))
- return
- #task2
- """
- -------------------------------------------------------
- [file name]
- [program description]
- -------------------------------------------------------
- Author: Prayrit Khanna
- ID: 160596860
- Email: khan6860@mylaurier.ca
- __updated__ = "2017-03-20"
- -------------------------------------------------------
- """
- from test_sorts_array import test_sort
- from sorts_array import Sorts
- sort = ('Insertion Sort', Sorts.insertion_sort)
- title = sort[0]
- func = sort[1]
- test_sort(title, func)
- #task3
- """
- -------------------------------------------------------
- [file name]
- [program description]
- -------------------------------------------------------
- Author: Prayrit Khanna
- ID: 160596860
- Email: khan6860@mylaurier.ca
- __updated__ = "2017-03-20"
- -------------------------------------------------------
- """
- from test_sorts_array import test_sort, SORTS
- from sorts_array import Sorts
- i = 0
- print ("{} |{:^15s}| |{:^30s}|".format("n: 100", "Comparisons", "Swaps"))
- while i<len(SORTS):
- sort = (SORTS[i])
- title = sort[0]
- func = sort[1]
- test_sort(title, func)
- i+= 1
- #task4
- """
- -------------------------------------------------------
- [file name]
- [program description]
- -------------------------------------------------------
- Author: Prayrit Khanna
- ID: 160596860
- Email: khan6860@mylaurier.ca
- __updated__ = "2017-03-20"
- -------------------------------------------------------
- """
- from test_sorts_array import test_sort, SORTS
- from sorts_linked import Sorts
- i = 0
- while i<len(SORTS):
- sort = (SORTS[i])
- title = sort[0]
- func = sort[1]
- test_sort(title, func)
- i+= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement