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 Delete(int index) { if (index >= this.count) { throw new Exception("Exception: there is no such element in linked list"); } if (index == 0) { this.Deletion(); } if (index == this.count - 1) { this.DeleteLast(); } if (index != 0 && index != this.count - 1) { int pointer = 0; DoublyLinkedListNode temp = this.head; while (pointer != index) { temp = temp.getNext(); pointer++; } temp.getPrev().setNext(temp.getNext()); temp.getNext().setPrev(temp.getPrev()); this.count--; } }