package dll;

class DllNode {
	DllNode prev;
	int value;
	DllNode next;

	public DllNode(int value) {
		this.value=value; // next and prev initialized to null already
	}

	public void addTail(int value) {
		if (next == null) {
			next = new DllNode(value);
			next.prev=this;
		} else next.addTail(value);
	}

	public String toString() {
		return "[" +
			((prev == null) ? "null" : prev.value) +
			"<-," + value + ",->" +
			((next == null) ? "null]" : next.value + "] " + next.toString());
	}

	public static void main(String args[]) {
		DllNode root = new DllNode(Integer.parseInt(args[0]));
		for(int i=1; i<args.length; i++) {
			root.addTail(Integer.parseInt(args[i]));
		}
		System.out.println("root is: " + root);
		root = null;
	}
}
