public void AddAfter(T itemToAdd) { SinglyLinkedNode <T> NextNode = new SinglyLinkedNode <T>(itemToAdd); NextNode.Next = Next; Next = NextNode; }
static void DisplayList(SinglyLinkedList <int> list) { if (list.Count == 0) { Console.WriteLine("List is empty."); } else { SinglyLinkedNode <int> node = list.Head; for (int i = 0; i < list.Count; i++) { Console.WriteLine($"{i + 1}) {node.Item}"); node = node.Next; } } }
public void AddToEnd(T itemToAdd) { var node = Head; if (node == null) { Head = new SinglyLinkedNode <T>(itemToAdd); } else { while (node.Next != null) { node = node.Next; } node.Next = new SinglyLinkedNode <T>(itemToAdd); } }
public void AddToFront(T itemToAdd) { SinglyLinkedNode <T> node = new SinglyLinkedNode <T>(itemToAdd, Head); Head = node; }
public void RemoveNext() { Next = Next.Next; }
public SinglyLinkedNode(T item, SinglyLinkedNode <T> next = null) { Item = item; Next = next; }