// assumes a non empty list: public DotnetLinkedList Delete(int key) { DotnetLinkedList currentLink = first; DotnetLinkedList previousLink = first; while (currentLink.key != key) { if (currentLink.next == null) { return(null); } previousLink = currentLink; currentLink = currentLink.next; } if (currentLink == first) { first = first.next; } else { //currentLink which is the node to be deleted will be bypass previousLink.next = currentLink.next; } return(currentLink); }
public void InsertFirst(int id, decimal value) { DotnetLinkedList newLink = new DotnetLinkedList(id, value); newLink.next = first; first = newLink; }
public DotnetLinkedList FindLinear(int key) { DotnetLinkedList currentLink = first; //start at the first link item while (currentLink.key != key) { if (currentLink.next == null) { return(null); } currentLink = currentLink.next; } return(currentLink); }
public void DeleteFirst() { first = first.next; }