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);
}
// removing last node
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP