Write a Java program that features a recursive method that takes
two linked lists A and B of objects and returns a list in
which the elements of A and B have been interleaved.
You may use the following starter code.
public class Interleave {
public static void main(String[] args) {
Node listA = Node.makeList5(0,4,8,12,16);
Node listB = Node.makeList5(1,5,9,13,17);
Node listC = Node.interleave(listA, listB);
Node.printList(listC);
}
}
class Node {
Object data;
Node next;
static Node addToFront(Object newData, Node oldList) {
Node n = new Node();
n.data = newData;
n.next = oldList;
return n;
}
Node addIntToFront(int i) {
return addToFront(new Integer(i),this);
}
static Node makeList5(int a,int b,int c,int d, int e) {
Node n = new Node();
n.data = new Integer(e);
n.next = null;
n = n.addIntToFront(d);
n = n.addIntToFront(c);
n = n.addIntToFront(b);
n = n.addIntToFront(a);
System.out.println("The result of makeList5 is ");
Node.printList(n);
return n;
}
static Node interleave(Node listA, Node listB) {
System.out.println("Entering interleave... ");
// put your code here.
}
static void printList(Node list) {
if (list == null) { System.out.println(); }
else {
System.out.println(list.data + "; ");
printList(list.next);
}
}
}
Test your program with a Java compiler and runtime system.
(For this assignment you are free to use the Java system of
your choice. Future assignments will require the use of Eclipse.
If you already know how to use Eclipse, you are welcome to
use it now.)
Turn in a printout of your code and of your test run's output.