// An example of a recursive stack. It's less efficient than other
// techniques we've seen because it does the terrible thing of pushing
// each item down the line, but the code is pretty clean.
// It is this kind of structure that I had in mind when creating
// the queue assignment that you're doing.
public class RStack
{
    private String item;
    private RStack next;

    public RStack()
    {
        item = null;
        next = null;
    }

    // An stack is one where item==null; a list with one item in
    // it has something in item, and next==null
    public void push(String value)
    {
        if (item == null)
        {
            item = value;
        }
        else if (next == null)
        {
            // Shove current value down
            next = new RStack();
            next.push(item);
            item = value;
        }
        else
        {
            next.push(item);
            item = value;
        }
    }

    // Yeah, this violates stackness, but I wanted it for debugging
    public void display()
    {
        if (item == null)
        {
            return;
        }
        else if (next == null)
        {
            System.out.println(item);
        }
        else
        {
            System.out.println(item);
            next.display();
        }
    }

    public static void main(String[] args)
    {
        RStack stack = new RStack();
        stack.push("hey");
        stack.push("happy");
        stack.push("train today");
        stack.push("green world");

        stack.display();
    }
}