// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   List.java


public class List
{

    public List()
    {
        head = null;
        last = null;
    }

    public void addTop(Object obj)
    {
        Node node = new Node(obj);
        if(head == null)
        {
            head = node;
            last = node;
        } else
        {
            node.link = head;
            head = node;
        }
    }

    public void addEnd(Object obj)
    {
        Node node = new Node(obj);
        if(head == null)
        {
            head = node;
            last = node;
        } else
        {
            last.link = node;
            last = node;
        }
    }

    public void addInPlace(Object obj)
    {
        Node node = head;
        Node node1 = new Node(obj);
        if(((String)node1.info).compareTo((String)node.info) < 1)
        {
            node1.link = head;
            head = node1;
            return;
        }
        for(; node.link != last && ((String)node1.info).compareTo((String)node.link.info) > 0; node = node.link);
        if(node.link == last && ((String)node1.info).compareTo((String)node.link.info) > 0)
        {
            last.link = node1;
            last = node1;
        } else
        if(node.link == last && ((String)node1.info).compareTo((String)node.link.info) < 0)
        {
            node.link = node1;
            node1.link = last;
        } else
        {
            node1.link = node.link;
            node.link = node1;
        }
    }

    public Object removeTop()
    {
        if(head == null)
            return null;
        Node node = head;
        head = head.link;
        node.link = null;
        if(head == null)
            last = null;
        return node.info;
    }

    public Object getObjectAt(int i)
    {
        if(i == 0)
            return head.info;
        Node node = head.link;
        boolean flag = false;
        for(int j = 0; j < i - 1; j++)
        {
            if(node == last)
                return null;
            node = node.link;
        }

        return node.info;
    }

    public String toString()
    {
        String s = "";
        for(Node node = head; node != null; node = node.link)
            s = s + node.info.toString();

        return s;
    }

    public String toFormattedString()
    {
        String s = "";
        for(Node node = head; node != null;)
        {
            s = s + (String)node.info;
            node = node.link;
            if(node != null)
                s = s + "\n";
        }

        return s;
    }

    public boolean objectExists(Object obj)
    {
        boolean flag = false;
        for(Node node = head; !flag && node != null;)
            if(node.info.equals(obj))
                flag = true;
            else
                node = node.link;

        return flag;
    }

    public Object removeObject(Object obj)
    {
        boolean flag = false;
        if(head.info.equals(obj))
            return removeTop();
        Node node;
        for(node = head; !flag && node.link != null;)
            if(node.link.info.equals(obj))
                flag = true;
            else
                node = node.link;

        if(flag)
        {
            Node node1 = node.link;
            node.link = node1.link;
            node1.link = null;
            return node1.info;
        } else
        {
            return null;
        }
    }

    Node head;
    Node last;
}

