/** * test node class * * to test: say "java testNode ... list of strings ..." * */ class testNode { // the next method is not particularly important: public static Node LastButOne(Node H) { if (H == null) return H; Node Prev = H; H = H.getNext(); if (H == null) return H; while (H.getNext() != null) { Prev = H; H = H.getNext(); } return Prev; } public static void main(String[] args) { Node a = Node.mkList(args); if (a == null) System.out.println("Empty list!"); Node b = LastButOne(a); if (b == null) System.out.println("List of one only: " + a.getItem()); System.out.println("Last but one node = " + b.getItem()); System.out.println("All the elements in list:"); a.print(); } }