

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to add a node after the given node in a Linked List
Set a LinkedList and add elements.
string [] students = {"Beth","Jennifer","Amy","Vera"}; LinkedList<string> list = new LinkedList<string>(students);
Firstly, add a new node at the end.
var newNode = list.AddLast("Emma");
Now, use the AddAfter() method to add a node after the given node.
list.AddAfter(newNode, "Matt");
The following is the complete code.
Example
using System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Beth","Jennifer","Amy","Vera"}; LinkedList<string> list = new LinkedList<string>(students); foreach (var stu in list) { Console.WriteLine(stu); } // adding a node at the end var newNode = list.AddLast("Emma"); // adding a new node after the node added above list.AddAfter(newNode, "Matt"); Console.WriteLine("LinkedList after adding new nodes..."); foreach (var stu in list) { Console.WriteLine(stu); } } }
Output
Beth Jennifer Amy Vera LinkedList after adding new nodes... Beth Jennifer Amy Vera Emma Matt
- Related Questions & Answers
- C# Program to add a node before the given node in a Linked List
- Golang Program to add the first node in a given linked list.
- Golang Program to add a node at the end of a given linked list.
- C# Program to add a node at the first position in a Linked List
- C# Program to add a node at the last position in a Linked List
- C++ Program to Delete the First Node in a given Singly Linked List
- Golang program to insert a new node after the Kth node (K is not in the linked list)
- Delete a Linked List node at a given position in C++
- Golang Program to delete the node after the Kth node (K is not in the linked list).
- C# program to find node in Linked List
- Delete a Doubly Linked List node at a given position in C++
- Delete a tail node from the given singly Linked List using C++
- Golang Program to insert a new node after the Kth node.
- C# Program to remove a node at the beginning of a Linked List
- Linked List Random Node in C++
Advertisements