/** LinkedListReverser.java reversed a linked list recursively.
 *  @author Joel Adams
 *
 */

import java.util.LinkedList;

public class LinkedListReverser {
    public static void reverse(LinkedList<Integer> aList) {
	if ( aList.size() > 1 ) {
		int firstItem = aList.removeFirst();
		reverse(aList);
		aList.add(firstItem);
	}
    }

    public static void main(String [] args) {
	LinkedList<Integer> theList = new LinkedList<Integer>();
	theList.add(11);
	theList.add(22);
	theList.add(33);
	theList.add(44);
	theList.add(55);
	System.out.println( "Before: " + theList );
	reverse(theList);
	System.out.println( "After: " + theList );
    }
}

