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 Insertion(double value) { DoublyLinkedListNode newNode = new DoublyLinkedListNode(value); if (this.head == null) { this.head = this.tail = newNode; } if (this.head != null) { newNode.setNext(this.head); this.head = newNode; newNode.getNext().setPrev(this.head); } this.count++; }