Example #1
0
 public void ClearAll()
 {
     if (sLinkedList.head != null)
     {
         while (sLinkedList.head != null)
         {
             SNode <T> firstNode = sLinkedList.head;
             sLinkedList.head = firstNode.next;
             firstNode        = null;
         }
     }
 }
Example #2
0
        public void Insert(T newData)
        {
            SNode <T> newNode = new SNode <T>(newData);

            if (sLinkedList.head == null)
            {
                sLinkedList.head = newNode;
            }
            else
            {
                SNode <T> last = FindLast(sLinkedList);
                last.next = newNode;
            }
        }
Example #3
0
        /// <summary>
        /// Return all data as a List
        /// </summary>
        /// <returns></returns>
        public List <T> GetAll()
        {
            List <T> list = new List <T>();

            if (sLinkedList.head != null)
            {
                SNode <T> current = sLinkedList.head;
                while (current != null)
                {
                    list.Add(current.data);
                    current = current.next;
                }
            }

            return(list);
        }
Example #4
0
 /// <summary>
 /// Console output
 /// </summary>
 public void DisplayAll()
 {
     if (sLinkedList.head == null)
     {
         Console.WriteLine("List is empty!");
     }
     else
     {
         SNode <T> current = sLinkedList.head;
         while (current != null)
         {
             Console.WriteLine(current.data);
             current = current.next;
         }
     }
 }
Example #5
0
 public SNode(T _data)
 {
     data = _data;
     next = null;
 }