Example #1
0
 /// <summary>
 /// Method, which adds a new eleent in the list
 /// </summary>
 /// <param name="value">value of an element</param>
 public void AddElement(int value)
 {
     if (IsEmpty())
     {
         ListElement tmp = new ListElement(null, value);
         head = tmp;
         tail = tmp;
     }
     else
     {
         ListElement tmp = new ListElement(null, value);
         tail.Next = tmp;
         tail = tmp;
     }
 }
Example #2
0
 /// <summary>
 /// Method, which deletes an element from the list
 /// </summary>
 /// <param name="value">value of the element, which is wanted to be deleted</param>
 /// <returns>value of deleted element</returns>
 public int DeleteElement(int value)
 {
     if (!IsEmpty())
     {
         if (head.Next != null)
         {
             if (head.Element == value)
             {
                 head = head.Next;
                 return value;
             }
             ListElement tmp = head;
             while (tmp.Next.Element != value && tmp != null)
             {
                 tmp = tmp.Next;
             }
             if (tmp == null)
             {
                 throw new NullReferenceException("This element doesn't exist");
             }
             else
             {
                 tmp.Next = tmp.Next.Next;
                 return tmp.Element;
             }
         }
         else
         {
             if (head.Element == value)
             {
                 int tmp = head.Element;
                 head = null;
                 return tmp;
             }
             else
             {
                 throw new NullReferenceException("This element doesn't exist");
             }
         }
     }
     else
     {
         throw new NullReferenceException("This element doesn't exist");
     }
 }
Example #3
0
 public ListElement(ListElement next, int value)
 {
     this.Next = next;
     this.Element = value;
 }