def test_append(): L = LinkedList() L.append_list("a") L.append_list("b") L.append_list("c") actual = L.value_list() print(actual) expected = ["a", "b", "c"] assert actual == expected
def test_insert_before(): L = LinkedList() L.append_list("a") L.append_list("b") L.append_list("c") L.insert_before("c", "z") actual = L.value_list() print(actual) expected = ["a", "b", "z", "c"] assert actual == expected L.insert_before("a", "y") actual = L.value_list() print(actual) expected = ["y", "a", "b", "z", "c"] assert actual == expected
def zip_list(list_one, list_two): # check if lists are linked lists if type(list_one) != LinkedList or type(list_two) != LinkedList: raise TypeError # start at the beginning of each list current_one = list_one.head current_two = list_two.head # create an empty linked list zipped_list = LinkedList() # while each node has is truthy while current_one and current_two: # append method adds new node and assigns appropriate next zipped_list.append_list(current_one.value) current_one = current_one.next_ # add list two node to zip, give it list two next zipped_list.append_list(current_two.value) current_two = current_two.next_ remainder = current_one if current_one else current_two while remainder: zipped_list.append_list(remainder.value) remainder = remainder.next_ return zipped_list