class IntList { public int first; public IntList rest; public IntList(int f, IntList r) { first = f; rest = r; } } public class Iteration { static int minInt = -10000; public static int findMaxIt(IntList L) { int max = minInt; while (L != null) { max = Math.max(L.first, max); L = L.rest; } return max; } public static int findMaxRec(IntList L) { if (L == null) { return minInt; } else { return Math.max(L.first, findMaxRec(L.rest)); } } static public void main(String args[]) { IntList L = new IntList(1, new IntList(7, new IntList(3, new IntList(4, null)))); int a = findMaxIt(L); int b = findMaxRec(L); System.out.println("Iterative: " + a); System.out.println("Recursive: " + b); } }