// Integer => ConsCell<E> => ConsCell<Integer>
public class ConsCell<E> {
  private E head;
  private ConsCell<E> tail;

  public ConsCell(E h, ConsCell<E> t) {
    head = h;
    tail = t;
  }

  public E getHead() {
    return head;
  }

  public ConsCell<E> getTail() {
    return tail;
  }

  public void print() {
    System.out.println(head);
    if (tail != null) {
      tail.print();
    }
  }

  public int length() {
    if (tail == null) {
      return 1;
    } else {
      return 1 + tail.length();
    }
  }

  public static void main(String argc[]) {
  ConsCell<Integer> c1=new ConsCell<Integer>(1, null);
  ConsCell<Integer> c2=new ConsCell<Integer>(2, c1);
  ConsCell<Integer> c3=new ConsCell<Integer>(3, c2);
  ConsCell<Integer> c4=new ConsCell<Integer>(4, c3);
    System.out.println(c4.length());
    System.out.println("Printing c4");
    c4.print();
    System.out.println("Printing c2");
    c2.print();
  }
}
