Write a function called zipLists
which takes two linked lists as arguments. Zip the two linked lists together into one so that the nodes alternate between the two lists and return a reference to the head of the zipped list. Try to keep additional space down to O(1).
Extend the linked list with this method:
zipLists(linkedListOne, LinkedListTwo)
(interleaveslinkedListOne
andlinkedListTwo
to a single linked list)
Input: a linked listlinkedListOne
and a linked listlinkedListTwo
Output: a reference to the head of the interleaved linked list
Edge case(s):
- Either linked list is empty (Throw error)
linkedListOne
is smaller thanlinkedListTwo
(Passes)linkedListTwo
is smaller thanlinkedListOne
(Passes)
Write tests to prove the following functionality:
linkedListOne
is smaller than linkedListTwo
linkedListTwo
is smaller than linkedListOne