- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Removing the node at the start of the LinkedList in C#
To remove the node at the start of the LinkedList, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList<string> list = new LinkedList<string>(); list.AddLast("One"); list.AddLast("Two"); list.AddLast("Three"); list.AddLast("Three"); list.AddLast("Three"); list.AddLast("Four"); Console.WriteLine("Count of nodes = " + list.Count); Console.WriteLine("Elements in LinkedList... (Enumerator iterating through LinkedList)"); LinkedList<string>.Enumerator demoEnum = list.GetEnumerator(); while (demoEnum.MoveNext()) { string res = demoEnum.Current; Console.WriteLine(res); } list.RemoveFirst(); Console.WriteLine("Count of nodes (UPDATED) = " + list.Count); Console.WriteLine("Elements in LinkedList... (Enumerator iterating through LinkedList)..UPDATED"); demoEnum = list.GetEnumerator(); while (demoEnum.MoveNext()) { string res = demoEnum.Current; Console.WriteLine(res); } } }
Output
This will produce the following output −
Count of nodes = 6 Elements in LinkedList... (Enumerator iterating through LinkedList) One Two Three Three Three Four Count of nodes (UPDATED) = 5 Elements in LinkedList... (Enumerator iterating through LinkedList)..UPDATED Two Three Three Three Four
Example
Let us see another example −
using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList<string> list = new LinkedList<string>(); list.AddLast("One"); list.AddLast("Two"); list.AddLast("Three"); list.AddLast("Three"); list.AddLast("Three"); list.AddLast("Four"); Console.WriteLine("Count of nodes = " + list.Count); Console.WriteLine("Elements in LinkedList... (Enumerator iterating through LinkedList)"); LinkedList<string>.Enumerator demoEnum = list.GetEnumerator(); while (demoEnum.MoveNext()) { string res = demoEnum.Current; Console.WriteLine(res); } list.RemoveFirst(); Console.WriteLine("Count of nodes (UPDATED) = " + list.Count); Console.WriteLine("Elements in LinkedList... (Enumerator iterating through LinkedList)..UPDATED"); demoEnum = list.GetEnumerator(); while (demoEnum.MoveNext()) { string res = demoEnum.Current; Console.WriteLine(res); } list.RemoveFirst(); Console.WriteLine("Count of nodes (UPDATED AGAIN) = " + list.Count); Console.WriteLine("Elements in LinkedList... (Enumerator iterating through LinkedList)..UPDATED AGAIN"); demoEnum = list.GetEnumerator(); while (demoEnum.MoveNext()) { string res = demoEnum.Current; Console.WriteLine(res); } } }
Output
This will produce the following output −
Count of nodes = 6 Elements in LinkedList... (Enumerator iterating through LinkedList) One Two Three Three Three Four Count of nodes (UPDATED) = 5 Elements in LinkedList... (Enumerator iterating through LinkedList)..UPDATED Two Three Three Three Four Count of nodes (UPDATED AGAIN) = 4 Elements in LinkedList... (Enumerator iterating through LinkedList)..UPDATED AGAIN Three Three Three Four
- Related Articles
- Adding new node or value at the start of LinkedList in C#
- Removing the specified node from the LinkedList in C#?
- Adding new node or value at the end of LinkedList in C#
- Get the first node of the LinkedList in C#
- Get the last node of the LinkedList in C#
- Find the first node in LinkedList containing the specified value in C#
- Find the last node in LinkedList containing the specified value in C#
- Removing all nodes from LinkedList in C#
- Removing an element from the start of the array in javascript
- Removing first occurrence of specified value from LinkedList in C#
- C# Program to remove a node at the end of the Linked List
- Adding an element at the start of the array in Javascript
- Removing a node in a Javascript Tree
- Golang Program to insert a node at the ith index node, when the index is at the 0th position in the linked list.
- Golang program to insert a node at the ith index node, when the index is at the last position in the linked list.

Advertisements