package CtCILibrary;

import java.util.ArrayList;

public class LinkedListNode {
	public LinkedListNode next;
	public LinkedListNode prev;
	public LinkedListNode last;
	public int data;
	public LinkedListNode(int d, LinkedListNode n, LinkedListNode p) {
		data = d;
		setNext(n);
		setPrevious(p);
	}
	
	public LinkedListNode() { }

	public void setNext(LinkedListNode n) {
		next = n;
		if (this == last) {
			last = n;
		}
		if (n != null && n.prev != this) {
			n.setPrevious(this);
		}
	}
	
	public void setPrevious(LinkedListNode p) {
		prev = p;
		if (p != null && p.next != this) {
			p.setNext(this);
		}
	}	
	
	public String printForward() {
		if (next != null) {
			return data + "->" + next.printForward();
		} else {
			return ((Integer) data).toString();
		}
	}
	
	public LinkedListNode clone() {
		LinkedListNode next2 = null;
		if (next != null) {
			next2 = next.clone();
		}
		LinkedListNode head2 = new LinkedListNode(data, next2, null);
		return head2;
	}

	public int[] toIntArray() {
		ArrayList<Integer> intArrayList = new ArrayList<Integer>();
		LinkedListNode node = this;
		while (node.next != null) {
			intArrayList.add(node.data);
			node = node.next;
		}
		int[] intArray = new int[intArrayList.size()];
		int i = 0;
		for (Integer n : intArrayList) {
			intArray[i] = n;
			i++;
		}
		return intArray;
	}
}

@@ -1394,11 +1394,183 @@
 y;%0D%0A%09%7D%0D%0A
+%0D%0A%09public int length() %7B%0D%0A%09%09int length = 1;%0D%0A%09%09LinkedListNode node = this;%0D%0A%09%09while (node.next != null) %7B%0D%0A%09%09%09node = node.next;%0D%0A%09%09%09length++;%0D%0A%09%09%7D%0D%0A%09%09return length;%0D%0A%09%7D%0D%0A%0D%0A
 %7D%0D%0A

Add length() method.