def test_sorted(self): t_list = random_list() sorted_list = t_list.copy() sorted_list.sort() perform_merge_sort(t_list) self.assertEqual(t_list, sorted_list)
first] <= search_key <= sorted_usr_list[end]: pos = first + ((end - first) // (sorted_usr_list[end] - sorted_usr_list[first]) * (search_key - sorted_usr_list[first])) if sorted_usr_list[pos] == search_key: return pos if sorted_usr_list[pos] < search_key: return perform_interpolation_search(sorted_usr_list, pos + 1, end, search_key) if sorted_usr_list[pos] > search_key: return perform_interpolation_search(sorted_usr_list, first, pos - 1, search_key) return -1 if __name__ == '__main__': usr_list = random_list(15, 25) perform_insertion_sort(usr_list) print(usr_list) searching_key = random_search_key() print("Searching for...", searching_key) print( "Found in index ", perform_interpolation_search(usr_list, 0, len(usr_list) - 1, searching_key))
else: usr_list[k] = right_list[j] j += 1 k += 1 while i < len(left_list): usr_list[k] = left_list[i] i += 1 k += 1 while j < len(right_list): usr_list[k] = right_list[j] j += 1 k += 1 if __name__ == '__main__': usr_list = random_list(10) print(usr_list) perform_merge_sort(usr_list) print(usr_list) class TestSortedList(unittest.TestCase): def test_sorted(self): t_list = random_list() sorted_list = t_list.copy() sorted_list.sort() perform_merge_sort(t_list) self.assertEqual(t_list, sorted_list)
def test_sorted(self): t_list = random_list(11) sorted_list = t_list.copy() sorted_list.sort() perform_quick_sort(t_list, 0, len(t_list) - 1) self.assertEqual(sorted_list, t_list)