/// <summary> /// Constructor for when a node is added to the end of the list. /// </summary> /// <param name="previous"></param> /// <param name="index"></param> public DoubleLinkListNode(DoubleLinkListNode previous, int index) { this.Previous = previous; this.Next = null; this.Index = index; if (this.Previous != null) { this.Previous.Next = this; } }
/// <summary> /// Constructor for when a node is inserted into the middle of the list. /// </summary> /// <param name="previous"></param> /// <param name="index"></param> public DoubleLinkListNode(DoubleLinkListNode previous, DoubleLinkListNode next) { this.Previous = previous; this.Next = next; this.Index = next.Index; if (this.Previous != null) { this.Previous.Next = this; } if (this.Next != null) { this.Next.Previous = this; IncrementForward(); } }
/// <summary> /// This function effectively removes this node from the linked list, /// and decrements the position index of all the nodes that follow it. /// It removes the node by changing the nodes that come before and /// after it to point to each other, thus bypassing this node. /// </summary> public void Remove() { if (this.Previous != null) { this.Previous.Next = this.Next; } if (this.Next != null) { this.Next.Previous = this.Previous; } DecrementForward(); }