Write a function called zip_lists
- Arguments: 2 linked lists
- Return: New Linked List, zipped as noted below
- Zip the two linked lists together into one so that the nodes alternate between the two lists and return a reference to the zipped list.
- Try and keep additional space down to O(1)
- This will use code from Linked List Insertions
Figjam Link for Code Challenge 8-- to navigate the image embedded above
In my code, I used one while loop and then an if conditional for each of the linked lists, then had each if conditional move across the nodes of both lists. Since my code wanted me to use the first list argument first in the zipping process, I put that one first in the while loop and list2 second. I suppose you could add more conditions.
Time: O(n+m)
- because you need to traverse both of the linked lists, even though I have it in a nested while loop
Space: O(n+m)
- this accounts for the space needed to store the nodes of the new linked list, which will have a number of nodes equal to the sum of the nodes in the two input lists
Terminal command: python3 -m linked_list_zip.linked_list_zip
Terminal command : python3 -m pytest linked_list_zip/


