public DoubleLink Insert(string title) { // Creates a link, sets its link to the first item and then makes this the first item in the list. DoubleLink link = new DoubleLink(title); link.NextLink = _first; if (_first != null) _first.PreviousLink = link; _first = link; return link; }
public DoubleLink Delete() { // Gets the first item, and sets it to be the one it is linked to DoubleLink temp = _first; if (_first != null) { _first = _first.NextLink; if (_first != null) _first.PreviousLink = null; } return temp; }
public DoubleLink Delete(DoubleLink link) { DoubleLink temp = _first; if (link == temp || link == null) temp = Delete (); else { if (link.PreviousLink != null) { link.PreviousLink.NextLink = link.NextLink; } if (link.NextLink != null) link.NextLink.PreviousLink = link.PreviousLink; temp = link.PreviousLink; } return temp; }
///// New operations public void InsertAfter(DoubleLink link, string title) { if (link == null || string.IsNullOrEmpty(title)) return; DoubleLink newLink = new DoubleLink(title); newLink.PreviousLink = link; // Update the 'after' link's next reference, so its previous points to the new one if (link.NextLink != null) link.NextLink.PreviousLink = newLink; // Steal the next link of the node, and set the after so it links to our new one newLink.NextLink = link.NextLink; link.NextLink = newLink; }
public DoubleLinkedList() { _first = null; }