import java.util.Scanner;


public class LinkStuff {

	public static class Node {
		String info;
		Node next;
		
		public Node(String str, Node link)
	    {
		   info = str;
		   next = link;
	    }
	}
	
	// addIter creates a new linked list with
	//    all the nodes from the Scanner in, in
	//    the same order.
	// pre: assume in has at least one item
	public Node addIter(Scanner in)
	{
		Node list = new Node(in.next(), null);
		Node current = list;
		while (in.hasNext())
		{
			// TODO: finish loop

			
		}
		return list;
	}
	
	// recursively add all the nodes from the
	//  scanner in into a linked list, with all 
	//  the values in the same order from the scanner
	public Node addRec(Scanner in)
	{
		// TODO:
		return null;
	}

	// ReverseAddIter creates a new linked list with
	//    all the nodes from the Scanner in, in
	//    the reverse order they appear in the scanner.
	// pre: assume in has at least one item	
	public Node reverseAddIter(Scanner in)
	{
		Node list = new Node(in.next(), null);

        // TODO: build list
		
		return list;
	}
	
	// recursively add all the nodes from the
	//  Scanner in into a linked list, in the reverse
	//  order they appear in Scanner
	//  assume there is at least one value in "in"
	public Node reverseAddRec(Scanner in)
	{
		Node temp = new Node(in.next(), null);
        // TODO: build list
		
		return temp;
	}
	
	// return a reference to the last node in the list
	// or return null if list is empty
	// Do recursively
	public Node lastNode(Node list)
	{
		if (list == null)
			return null;
		
		// TODO: Return last node
        return list;
	}
	
	public void print(Node list)
	{
       // TODO:
	}
	
	// double the size of the list, do recursively
	//  a -> b -> c  would now be
	//  a -> a -> b -> b -> c -> c
	public Node doubleList (Node list)
	{
        // TODO:

		return list;
		
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		LinkStuff stuff = new LinkStuff();
		
		String data = "fa so la";
		Scanner input = new Scanner(data);
		System.out.print("calling addIter: ");
		Node itemlist = stuff.addIter(input);		
		stuff.print(itemlist);
		
		data = "do re me fa so la ti";
		input = new Scanner(data);
		System.out.print("calling addIter: ");
		itemlist = stuff.addIter(input);
		stuff.print(itemlist);
		
		data = "fa so la";
		input = new Scanner(data);
		System.out.print("calling addRec: ");
		itemlist = stuff.addRec(input);
		stuff.print(itemlist);

		data = "do re me fa so la ti";
		input = new Scanner(data);
		System.out.print("calling addRec: ");
		itemlist = stuff.addRec(input);
		stuff.print(itemlist);
		
		data = "fa so la";
		input = new Scanner(data);
		System.out.print("calling reverseAddIter: ");
		itemlist = stuff.reverseAddIter(input);
		stuff.print(itemlist);

		data = "do re me fa so la ti";
		input = new Scanner(data);
		System.out.print("calling reverseAddIter: ");
		itemlist = stuff.reverseAddIter(input);
		stuff.print(itemlist);
		System.out.println("Last node is " + stuff.lastNode(itemlist).info);
		
		data = "fa so la";
		input = new Scanner(data);
		System.out.print("calling reverseAddRec: ");
		itemlist = stuff.reverseAddRec(input);
		stuff.print(itemlist);

		data = "do re me fa so la ti";
		input = new Scanner(data);
		System.out.print("calling reverseAddRec: ");
		itemlist = stuff.reverseAddRec(input);
		stuff.print(itemlist);
		
		data = "me fa so la";
		input = new Scanner(data);
		System.out.print("calling addIter, then doubleList: ");
		itemlist = stuff.addIter(input);
		stuff.print(itemlist);
		itemlist = stuff.doubleList(itemlist);
		stuff.print(itemlist);

	}

}
