Set a LinkedList with nodes.
string [] students = {"Tim","Jack","Henry","David","Tom"};
LinkedList<string> list = new LinkedList<string>(students);Now, use the AddLast() method to add a node at the last position.
list.AddLast("Kevin");Here is the complete code with the updated LinkedList.
Example
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
Console.WriteLine("LinkedList after adding a node at the last position...");
list.AddLast("Kevin");
foreach (var stu in list) {
Console.WriteLine(stu);
}
}
}Output
Tim Jack Henry David Tom LinkedList after adding a node at the last position... Tim Jack Henry David Tom Kevin