먼저 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