Example #1
0
 public void InsertStart(T item)
 {
     if (_head == null)
     {
         _head = new LinkedNode <T>(item);
     }
     else
     {
         _head = new LinkedNode <T>(item, _head);
     }
 }
Example #2
0
 public void InsertEnd(T item)
 {
     if (_head == null)
     {
         _head = new LinkedNode <T>(item);
     }
     else
     {
         LinkedNode <T> current = _head;
         while (current.Next != null)
         {
             current = current.Next;
         }
         current.Next = new LinkedNode <T>(item);
     }
 }
Example #3
0
        public LinkedNode <T> Search(T item)
        {
            LinkedNode <T> current = _head;

            while (current != null)
            {
                if (current.Item.Equals(item))
                {
                    return(current);
                }
                else
                {
                    current = current.Next;
                }
            }

            throw new ArgumentOutOfRangeException("Does not find the item.");
        }
Example #4
0
 public void Delete(T item)
 {
     if (_head != null)
     {
         if (_head.Item.Equals(item))
         {
             _head = null;
         }
         else
         {
             LinkedNode <T> current = _head;
             while (current.Next != null)
             {
                 if (current.Next.Item.Equals(item))
                 {
                     current.Next = current.Next.Next;
                     break;
                 }
             }
         }
     }
 }
Example #5
0
 public LinkedNode(T item, LinkedNode <T> next)
 {
     Item = item;
     Next = next;
 }