import java.io.*; class UseLists1 { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str; List l1, l2, l3; System.out.println("Enter list 1: "); str = in.readLine(); l1 = List.fromString(str); System.out.println("Enter list 2: "); str = in.readLine(); l2 = List.fromString(str); l3 = append(l1,l2); System.out.println("Appending the first to the second gives: "); System.out.println(l3); l3 = revAppend(l1,l2); System.out.println("Reversed appending the first to the second gives: "); System.out.println(l3); System.out.println("The lists are still: "); System.out.println(l1); System.out.println(l2); } public static List append(List l1,List l2) { if(l1.isEmpty()) return l2; else return append(l1.tail(),l2).cons(l1.head()); } public static List revAppend(List l1,List l2) { while(!l1.isEmpty()) { l2=l2.cons(l1.head()); l1=l1.tail(); } return l2; } }