public void InsertAfter(double value, int index) { if (index == 0) { this.Insertion(value); } if (index == this.count) { this.InsertLast(value); } if (index != 0 && index != this.count) { int pointer = 0; DoublyLinkedListNode temp = this.head; DoublyLinkedListNode newNode = new DoublyLinkedListNode(value); while (pointer != index) { temp = temp.getNext(); pointer++; } temp.getPrev().setNext(newNode); newNode.setPrev(temp.getPrev()); temp.setPrev(newNode); newNode.setNext(temp); this.count++; } }
public void InsertLast(double value) { DoublyLinkedListNode newNode = new DoublyLinkedListNode(value); if (this.head == null) { this.head = this.tail = newNode; } if (this.head != null) { this.tail.setNext(newNode); newNode.setPrev(this.tail); this.tail = newNode; } this.count++; }