public class List {
    public int info;
    public List next;

    // Konstruktoren:
    public List (int x, List l) {
        info = x;
        next = l;
    }
    public List (int x) {
        info = x;
        next = null;
    }
    // Objekt-Methoden:
    public void insert(int x) {
        next = new List(x,next);
    }
    public void delete() {
        if (next != null)
            next = next.next;
    }
    public String toString() {
        String result = "[" + info;
        for(List t = next; t != null; t = t.next)
            result = result + ", " + t.info;
        return result + "]";
    }
    // Klassen-Methoden:
    public static boolean isEmpty(List l) {
        return (l == null);
    }
    public static String toString(List l) {
        if (l == null) 
            return "[]";
        else
            return l.toString();
    }
    public static List arrayToList(int[] a) {
        List result = null;
        for(int i = a.length-1; i >= 0; --i)
            result = new List(a[i], result);
        return result;
    }
    public int[] listToArray() {
        List t  = this;
        int n   = length();
        int[] a = new int[n];
        for(int i = 0; i < n; ++i) {
            a[i] = t.info;
            t = t.next;
        }
        return a;
    }
    private int length() {
        int result = 1;
        for(List t = next; t != null; t = t.next)
            result++;
        return result;
    }

    public static int length(List l) {
        if (l == null) return 0;
        return l.length();
    }

    public List half() {
        int n = length();
        List t = this;
        for (int i = 0; i < n/2-1; i++)
            t = t.next;
        List result = t.next;
        t.next = null;
        return result;
    }

    // Jetzt kommt das Hauptprogramm
    public static void main(String[] args) {
        List l = new List(1);
        l.insert(2);
        l.insert(3);
        l.insert(4);
        l.insert(5);

        System.out.println(""+l);
    } // end of main()      
} // end of class List
