class LinkedList ext ProxifiedObject {
  Value val
  LinkedList next

  void init(Value x) {
    this.val := x;
    this.next := null
  }

  void add(LinkedList x) {
    this.next := x
  }

  void print(Dummy x) {
    out.nextPutAll("LinkedList[");
    this.printVal(false);
    out.nextPutAll("]");
    out.cr
  }

  void printVal(bool x) {
    if (x) {
      out.nextPutAll(", ")
    } else {
      x
    };
    out.print(this.val);
    if (this.next == null) {
      x
    } else {
      this.next.printVal(true)
    }
  }
}

class TestLinkedList ext ProxifiedObject {
  LinkedList l
  LinkedList l2
  LinkedList l3

  void main(TestLinkedList x) {
    out.println("testing LinkedList");

    x.l := new LinkedList;
    x.l.init(55);

    x.l2 := new LinkedList;
    x.l2.init(1105);
    x.l.add(x.l2);

    x.l3 := new LinkedList;
    x.l3.init(1);
    x.l2.add(x.l3);

    x.l.print(x); 
  }
}
