C# 程序在链表中删除第一个出现的节点
以下是我们的带有节点的链表列表。
string [] students = {"Katie","Jennifer","Amy","Vera"}; LinkedList<string> list = new LinkedList<string>(students);
现在让我们删除一个包含字符串元素“Vera”的节点。
为此,请使用 Remove() 方法。
list.Remove("Vera");
示例
using System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Katie","Jennifer","Amy","Vera"}; LinkedList<string> list = new LinkedList<string>(students); foreach (var stu in list) { Console.WriteLine(stu); } // removing a node list.Remove("Vera"); Console.WriteLine("LinkedList after removing a node..."); foreach (var stu in list) { Console.WriteLine(stu); } } }
输出
Katie Jennifer Amy Vera LinkedList after removing a node... Katie Jennifer Amy
广告