Q3 List Interleaving
15 Points
Q3.1 Code
10 Points
Write a function that takes two lists and interleaves them. The result should be a new list which
alternates elements from the two lists, starting with the first element of the first list, and stopping
when no element can be extracted from a list. For full credit, write a single recursive function
with a single decision or conditional.
Below is the code for the list interface:
function empty() { return { isEmpty: () => true }; }
function node (data, next) {
return { head: () => data, tail: () => next,
isEmpty: () => false };
}
Enter your answer here
Note: "alternates" means from one list, then from the other list, repeated. That is, if the lists are
a1, a2, ... and b1, b2, ... it will be a1, b1, a2, b2, ...
Q3.2 Test
5 Points
Write five sample inputs to test the code you wrote in part 1. Explain what each input set is
testing for. You may simply write lists as enumeration of elements.
Enter your answer here