LinkedList घोषित करें और उसमें नोड जोड़ें।
string [] students = {"Tim","Jack","Henry","David","Tom"}; LinkedList<string> list = new LinkedList<string>(students);
आइए एक नया नोड जोड़ें।
var newNode = list.AddLast("Kevin");
अब, दिए गए नोड से पहले एक नोड जोड़ने के लिए, AddBefore () विधि का उपयोग करें।
list.AddBefore(newNode, "Matt");
आइए अब पूरा कोड देखें।
उदाहरण
using System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Tim","Jack","Henry","David","Tom"}; LinkedList<string> list = new LinkedList<string>(students); foreach (var stu in list) { Console.WriteLine(stu); } // adding a node at the end var newNode = list.AddLast("Kevin"); // adding a new node before the node added above list.AddBefore(newNode, "Matt"); Console.WriteLine("LinkedList after adding new nodes..."); foreach (var stu in list) { Console.WriteLine(stu); } } }
आउटपुट
Tim Jack Henry David Tom LinkedList after adding new nodes... Tim Jack Henry David Tom Matt Kevin