public void print() { DoubleNode tmp = head; while (tmp != null) { Console.WriteLine(tmp.data); tmp = tmp.next; } }
private DoubleNode lastNode(DoubleLinkedList list) { DoubleNode tmp = list.head; while (tmp.next != null) { tmp = tmp.next; } return(tmp); }
public void insert(int data) { DoubleLinkedList list = this; DoubleNode newNode = new DoubleNode(data); if (list.head == null) { newNode.prev = null; list.head = newNode; return; } else { DoubleNode prevNode = lastNode(list); prevNode.next = newNode; newNode.prev = prevNode; } }
public DoubleNode(int data) { this.data = data; prev = null; next = null; }