public class PhoneList {
private PhoneNode head;
public PhoneList() {
head = null;
}
public void add(String name, String number) {
PhoneNode newNode = new PhoneNode(name, number);
newNode.setNext(head);
head = newNode;
}
public void print() {
printRecur(head);
}
private void printRecur(PhoneNode current) {
if (current != null) {
current.print();
printRecur(current.getNext());
}
}
public static void main(String [] args) {
String [] names = {"Alice", "Bob", "Mallory"};
String [] numbers = {"1", "2", "3"};
PhoneList phoneList = new PhoneList();
for (int i=names.length-1; i>=0; i--){
phoneList.add(names[i], numbers[i]);
}
phoneList.print();
}
}