C# Program to remove a node at the end of the Linked List


The following is our LinkedList.

string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"};
LinkedList<string> list = new LinkedList<string>(employees);

Now, let’s say you need to remove the last node i.e. “Jamie”. For that, use the RemoveLast() method.

list.RemoveLast();

Example

 Live Demo

using System;
using System.Collections.Generic;
class Demo {
   static void Main() {
      string [] employees = {"Patrick","Robert","John","Jacob", "Jamie"};
      LinkedList<string> list = new LinkedList<string>(employees);
      foreach (var emp in list) {
         Console.WriteLine(emp);
      }
      // removing last node
      list.RemoveLast();
      Console.WriteLine("LinkedList after removing last node...");
      foreach (var emp in list) {
         Console.WriteLine(emp);
      }
   }
}

Output

Patrick
Robert
John
Jacob
Jamie
LinkedList after removing last node...
Patrick
Robert
John
Jacob

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Jun-2020

88 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements