// 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()));
         }
     }
 }
 public SingleLinkedList()
 {
     _head = new SingleLinkedListNode <Item>(default, null);
Ejemplo n.º 5
0
 public SLLNode(T value, ISingleLinkedListNode <T> tail)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 public void SetTail(ISingleLinkedListNode <T> tail)
 {
     throw new NotImplementedException();
 }
 // Insertions
 public void Insert(T value)
 {
     head = new SLLNode <T>(value, head);
 }
Ejemplo n.º 8
0
 public SingleLinkedListNode(T value, ISingleLinkedListNode <T> next)
 {
     Value = value;
     Next  = next;
 }