// Deletions public void DeleteHead() { ISingleLinkedListNode <T> temp = head; head = temp.GetNext(); temp.Disconnect(); }
public void InsertAtEnd(T value) { if (head.IsEmpty()) { this.Insert(value); } else { ISingleLinkedListNode <T> temp = head; while (!temp.GetNext().IsEmpty()) { temp = temp.GetNext(); } temp.SetTail(new SLLNode <T>(value, temp.GetNext())); } }
public void InsertAfter(T value, T targetValue) { if (head.IsEmpty()) { throw new Exception("SLL is empty!"); } else { ISingleLinkedListNode <T> temp = head; while (!temp.IsEmpty() && !Equals(temp.GetValue(), targetValue)) { temp = temp.GetNext(); } if (temp.IsEmpty()) { throw new Exception("TagetValue not found within the list!"); } else { temp.SetTail(new SLLNode <T>(value, temp.GetNext())); } } }