C#程序在链接列表的最后位置添加节点
设置带有节点的LinkedList。
string [] students = {"Tim","Jack","Henry","David","Tom"};LinkedList<string> list = new LinkedList<string>(students);
现在,使用该AddLast()
方法在最后一个位置添加节点。
list.AddLast("Kevin");
这是带有更新的LinkedList的完整代码。
示例
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);
}
//在最后添加一个节点
Console.WriteLine("LinkedList after adding a node at the last position...");
list.AddLast("Kevin");
foreach (var stu in list) {
Console.WriteLine(stu);
}
}
}
输出结果
TimJack
Henry
David
Tom
LinkedList after adding a node at the last position...
Tim
Jack
Henry
David
Tom
Kevin
以上是 C#程序在链接列表的最后位置添加节点 的全部内容, 来源链接: utcz.com/z/335245.html