public void ClearAll() { if (sLinkedList.head != null) { while (sLinkedList.head != null) { SNode <T> firstNode = sLinkedList.head; sLinkedList.head = firstNode.next; firstNode = null; } } }
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; } }
/// <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); }
/// <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; } } }
public SNode(T _data) { data = _data; next = null; }