public class StringList {
    private Element head;

    public StringList() {
        head = new Element(null);
        head.next = head;
    }

    public String first() {
        return head.next.s;
    }

    public void pushFront(String s) {
        if (s == null) return;
        Element e = new Element(s);
        e.next = head.next;
        head.next = e;
    }

    public String popFront() {
        String s = first();
        head.next = head.next.next;
        return s;
    }

    public boolean contains(String s) {
        head.s = s;
        Element e = head.next;
        while (!e.s.equals(s)) {
            e = e.next;
        }
        head.s = null;
        return e != head;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder().append("(");
        Element e = head;
        while (e.next.next != head) {
            sb.append(e.next.s).append(", ");
            e = e.next;
        }
        sb.append(e.next.s).append(")");
        return sb.toString();
    }

    private static class Element {
        private String s;
        private Element next;

        private Element(String s) {
            this.s = s;
        }
    }

    public static void main(String[] args) {
        StringList movies = new StringList();

        movies.pushFront("Fightclub");
        movies.pushFront("Memento");
        movies.pushFront("Oldboy");
        movies.pushFront("Der Hobbit");
        movies.pushFront("Der Herr der Ringe");
        System.out.println(movies.toString());

        System.out.println(movies.contains("Memento"));
        System.out.println(movies.contains("Twilight"));
        System.out.println(movies.first());
        System.out.println(movies.popFront());
        System.out.println(movies.first());
    }
}
