First, create a new linked list -
LinkedList<string> myList = new LinkedList<string>();
Now add some elements in the linked list -
// Add 6 elements in the linked list myList.AddLast("P"); myList.AddLast("Q"); myList.AddLast("R"); myList.AddLast("S"); myList.AddLast("T"); myList.AddLast("U");
Now let’s find A node and add a new node after it -
LinkedListNode<string> node = myList.Find("R"); myList.AddAfter(node, "ADDED");
You can try running the following code to find the node in the linked list.
Live Demo< /p>
using System; using System.Collections.Generic; class Program { static void Main() { LinkedList<string> myList = new LinkedList<string>(); // Add 6 elements in the linked list myList.AddLast("P"); myList.AddLast("Q"); myList.AddLast("R"); myList.AddLast("S"); myList.AddLast("T"); myList.AddLast("U"); LinkedListNodenode = myList.Find("R"); myList.AddAfter(node, "ADDED"); foreach (var i in myList) { Console.WriteLine(i); } } }
P Q R ADDED S T U
The above is the detailed content of C# program to find nodes in linked list. For more information, please follow other related articles on the PHP Chinese website!