C#中的LinkedList RemoveLast()方法
首先,声明一个LinkedList并添加节点。
int [] num = {92, 98, 110, 130, 145, 170, 230, 240, 250, 300, 330};
LinkedList<int> myList = new LinkedList<int>(num);使用RemoveLast()方法从LinkedList中删除最后一个节点。
myList.RemoveLast();
示例
using System;
using System.Collections.Generic;
class Demo {
static void Main() {
int [] num = {92, 98, 110, 130, 145, 170, 230, 240, 250, 300, 330};
LinkedList<int> myList = new LinkedList<int>(num);
foreach (var n in myList) {
Console.WriteLine(n);
}
//删除最后一个节点
myList.RemoveLast();
Console.WriteLine("LinkedList after removing the last node...");
foreach (var n in myList) {
Console.WriteLine(n);
}
}
}输出结果
92 98 110 130 145 170 230 240 250 300 330 LinkedList after removing the last node... 92 98 110 130 145 170 230 240 250 300