/// <summary> /// This method is used to test the Linked Lists in the console. /// </summary> static void TestLL() { LinkdList ll = new LinkdList(new Node(10)); ll.Add(new Node(15)); ll.Add(new Node(20)); ll.Print(); // 20 -> 15 -> 10 -> NULL; Console.WriteLine(); Console.WriteLine("Let's find Node 10"); Node found = ll.Find(10); Console.WriteLine(found.Value); Node n3 = new Node(27); Node n6 = new Node(12); Node n7 = new Node(24); ll.AddBefore(n3, ll.Find(15)); ll.AddAfter(n6, ll.Find(27)); ll.AddLast(n7); ll.Print(); Console.WriteLine(); // 20 -> 27 -> 12 -> 15 -> 10 -> 24 -> NULL; }
public void LLCanAddBefore(object value) { Node node1 = new Node(0, 7); Node node2 = new Node(0, "cat"); Node node3 = new Node(0, "dog"); Node node4 = new Node(0, value); LinkdList list = new LinkdList(node1); list.Append(node2); list.Append(node3); list.AddBefore(node4, node3); Assert.Equal(value, list.Find(value).Value); }
static void Main(string[] args) { Console.WriteLine("Hello World!\n"); Node node1 = new Node(0, 7); Node node2 = new Node(0, "cat"); Node node3 = new Node(0, "dog"); Node node4 = new Node(0, 14); Node node5 = new Node(0, "bird"); LinkdList list = new LinkdList(node1); list.Add(node2); list.Append(node3); list.AddBefore(node4, node1); list.AddAfter(node5, node3); list.Print(); object searchTerm = 14; Node foundNode = list.Find(searchTerm); Console.WriteLine($"You searched for {searchTerm} and found {foundNode.Value}"); }