import java.io.*; class UseCharListsA6 { // Shows destructive append and change on lists // using recursion public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); CharListA L1=null,L2=null; char ch1,ch2; try { System.out.print("Enter first list of characters: "); L1 = CharListAIO.read(in); System.out.print("Enter second list of characters: "); L2 = CharListAIO.read(in); } catch(ListFormatException e) { System.out.println("Error: "+e.getMessage()); } System.out.print("The lists are: "); CharListAIO.print(L1); System.out.print(" and "); CharListAIO.print(L2); System.out.println(); System.out.println("Call destructive append "); destAppend(L1,L2); System.out.print("The lists are now: "); CharListAIO.print(L1); System.out.print(" and "); CharListAIO.print(L2); System.out.println(); System.out.print("Enter first character: "); ch1=in.readLine().charAt(0); System.out.print("Enter second character: "); ch2=in.readLine().charAt(0); System.out.print("Call destructive change of first to "); System.out.println("second character"); System.out.println("in second list "); destChange(ch1,ch2,L2); System.out.print("The lists are now: "); CharListAIO.print(L1); System.out.print(" and "); CharListAIO.print(L2); System.out.println(); } public static void destAppend(CharListA L1,CharListA L2) { if(L1.tail!=null) destAppend(L1.tail,L2); else L1.tail=L2; } public static void destChange(char ch1,char ch2,CharListA L) { if(L!=null) { destChange(ch1,ch2,L.tail); if(L.head==ch1) L.head=ch2; } } }