- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
C# Program to add a node at the last position in a Linked List
Set a LinkedList with nodes.
string [] students = {"Tim","Jack","Henry","David","Tom"}; LinkedList<string> list = new LinkedList<string>(students);
Now, use the AddLast() method to add a node at the last position.
list.AddLast("Kevin");
Here is the complete code with the updated LinkedList.
Example
using System; using System.Collections.Generic; class Demo { static void Main() { string [] students = {"Tim","Jack","Henry","David","Tom"}; LinkedList<string> list = new LinkedList<string>(students); foreach (var stu in list) { Console.WriteLine(stu); } // adding a node at the end Console.WriteLine("LinkedList after adding a node at the last position..."); list.AddLast("Kevin"); foreach (var stu in list) { Console.WriteLine(stu); } } }
Output
Tim Jack Henry David Tom LinkedList after adding a node at the last position... Tim Jack Henry David Tom Kevin
Advertisements