using C_.Datastructures.Nodes; namespace C_.Datastructures { public class LinkedList { public Node? Head { get; set; } = default(Node); private int Count { get; set; } = 0; public static LinkedList Create(){ //Create a new empty list return new LinkedList(); } public static LinkedList Create(T value){ //Create a new Class with a single item return new LinkedList(){ Head = Node.Create(value, null), Count = 1 }; } public static LinkedList Create(LinkedList list1, LinkedList list2){ //Append a previous list to a new List LinkedList list; list = list1; if (list == null || list.Count == 0) { //If list 2 is the only list present return list2; } //Find end of list and append fist item of next list if (list2 == null || list.Count == 0) return list; Node? end = list.Traverse(); end!.Next = list2!.Head; list.Count += list2!.Count; return list; } public void Add(T value){ Node newItem = Node.Create(value, default(Node)); Count++; //Set head to new item if list is empty if (Head == null) { Head = newItem; return; } //Find last item in list Node? end = Head; if (end != null) { end = Traverse(); } //Append item to end end!.Next = new Node{ Value = value, Next = default(Node) }; } private Node? Traverse(){ //Start at Head of list Node? node = Head; if (node != null) { //continue to end of list while (node!.Next != default(Node)) { node = (Node)node.Next; } } return node; } private Node? Traverse(Node start){ //Start at given point in list Node? node = start; if (node != null) { //Continue to end of list while (node!.Next != default(Node)) { node = (Node)node.Next; } } return node; } } }