
Domains
Agile Management
Master Agile methodologies for efficient and timely project delivery.
View All Agile Management Coursesicon-refresh-cwCertifications
Scrum Alliance
16 Hours
Best Seller
Certified ScrumMaster (CSM) CertificationScrum Alliance
16 Hours
Best Seller
Certified Scrum Product Owner (CSPO) CertificationScaled Agile
16 Hours
Trending
Leading SAFe 6.0 CertificationScrum.org
16 Hours
Professional Scrum Master (PSM) CertificationScaled Agile
16 Hours
SAFe 6.0 Scrum Master (SSM) CertificationAdvanced Certifications
Scaled Agile, Inc.
32 Hours
Recommended
Implementing SAFe 6.0 (SPC) CertificationScaled Agile, Inc.
24 Hours
SAFe 6.0 Release Train Engineer (RTE) CertificationScaled Agile, Inc.
16 Hours
Trending
SAFe® 6.0 Product Owner/Product Manager (POPM)IC Agile
24 Hours
ICP Agile Certified Coaching (ICP-ACC)Scrum.org
16 Hours
Professional Scrum Product Owner I (PSPO I) TrainingMasters
32 Hours
Trending
Agile Management Master's Program32 Hours
Agile Excellence Master's ProgramOn-Demand Courses
Agile and ScrumRoles
Scrum MasterTech Courses and Bootcamps
Full Stack Developer BootcampAccreditation Bodies
Scrum AllianceTop Resources
Scrum TutorialProject Management
Gain expert skills to lead projects to success and timely completion.
View All Project Management Coursesicon-standCertifications
PMI
36 Hours
Best Seller
Project Management Professional (PMP) CertificationAxelos
32 Hours
PRINCE2 Foundation & Practitioner CertificationAxelos
16 Hours
PRINCE2 Foundation CertificationAxelos
16 Hours
PRINCE2 Practitioner CertificationSkills
Change ManagementMasters
Job Oriented
45 Hours
Trending
Project Management Master's ProgramUniversity Programs
45 Hours
Trending
Project Management Master's ProgramOn-Demand Courses
PRINCE2 Practitioner CourseRoles
Project ManagerAccreditation Bodies
PMITop Resources
Theories of MotivationCloud Computing
Learn to harness the cloud to deliver computing resources efficiently.
View All Cloud Computing Coursesicon-cloud-snowingCertifications
AWS
32 Hours
Best Seller
AWS Certified Solutions Architect - AssociateAWS
32 Hours
AWS Cloud Practitioner CertificationAWS
24 Hours
AWS DevOps CertificationMicrosoft
16 Hours
Azure Fundamentals CertificationMicrosoft
24 Hours
Best Seller
Azure Administrator CertificationMicrosoft
45 Hours
Recommended
Azure Data Engineer CertificationMicrosoft
32 Hours
Azure Solution Architect CertificationMicrosoft
40 Hours
Azure DevOps CertificationAWS
24 Hours
Systems Operations on AWS Certification TrainingAWS
24 Hours
Developing on AWSMasters
Job Oriented
48 Hours
New
AWS Cloud Architect Masters ProgramBootcamps
Career Kickstarter
100 Hours
Trending
Cloud Engineer BootcampRoles
Cloud EngineerOn-Demand Courses
AWS Certified Developer Associate - Complete GuideAuthorized Partners of
AWSTop Resources
Scrum TutorialIT Service Management
Understand how to plan, design, and optimize IT services efficiently.
View All DevOps Coursesicon-git-commitCertifications
Axelos
16 Hours
Best Seller
ITIL 4 Foundation CertificationAxelos
16 Hours
ITIL Practitioner CertificationPeopleCert
16 Hours
ISO 14001 Foundation CertificationPeopleCert
16 Hours
ISO 20000 CertificationPeopleCert
24 Hours
ISO 27000 Foundation CertificationAxelos
24 Hours
ITIL 4 Specialist: Create, Deliver and Support TrainingAxelos
24 Hours
ITIL 4 Specialist: Drive Stakeholder Value TrainingAxelos
16 Hours
ITIL 4 Strategist Direct, Plan and Improve TrainingOn-Demand Courses
ITIL 4 Specialist: Create, Deliver and Support ExamTop Resources
ITIL Practice TestData Science
Unlock valuable insights from data with advanced analytics.
View All Data Science Coursesicon-dataBootcamps
Job Oriented
6 Months
Trending
Data Science BootcampJob Oriented
289 Hours
Data Engineer BootcampJob Oriented
6 Months
Data Analyst BootcampJob Oriented
288 Hours
New
AI Engineer BootcampSkills
Data Science with PythonRoles
Data ScientistOn-Demand Courses
Data Analysis Using ExcelTop Resources
Machine Learning TutorialDevOps
Automate and streamline the delivery of products and services.
View All DevOps Coursesicon-terminal-squareCertifications
DevOps Institute
16 Hours
Best Seller
DevOps Foundation CertificationCNCF
32 Hours
New
Certified Kubernetes AdministratorDevops Institute
16 Hours
Devops LeaderSkills
KubernetesRoles
DevOps EngineerOn-Demand Courses
CI/CD with Jenkins XGlobal Accreditations
DevOps InstituteTop Resources
Top DevOps ProjectsBI And Visualization
Understand how to transform data into actionable, measurable insights.
View All BI And Visualization Coursesicon-microscopeBI and Visualization Tools
Certification
24 Hours
Recommended
Tableau CertificationCertification
24 Hours
Data Visualization with Tableau CertificationMicrosoft
24 Hours
Best Seller
Microsoft Power BI CertificationTIBCO
36 Hours
TIBCO Spotfire TrainingCertification
30 Hours
Data Visualization with QlikView CertificationCertification
16 Hours
Sisense BI CertificationOn-Demand Courses
Data Visualization Using Tableau TrainingTop Resources
Python Data Viz LibsCyber Security
Understand how to protect data and systems from threats or disasters.
View All Cyber Security Coursesicon-refresh-cwCertifications
CompTIA
40 Hours
Best Seller
CompTIA Security+EC-Council
40 Hours
Certified Ethical Hacker (CEH v12) CertificationISACA
22 Hours
Certified Information Systems Auditor (CISA) CertificationISACA
40 Hours
Certified Information Security Manager (CISM) Certification(ISC)²
40 Hours
Certified Information Systems Security Professional (CISSP)(ISC)²
40 Hours
Certified Cloud Security Professional (CCSP) Certification16 Hours
Certified Information Privacy Professional - Europe (CIPP-E) CertificationISACA
16 Hours
COBIT5 Foundation16 Hours
Payment Card Industry Security Standards (PCI-DSS) CertificationOn-Demand Courses
CISSPTop Resources
Laptops for IT SecurityWeb Development
Learn to create user-friendly, fast, and dynamic web applications.
View All Web Development Coursesicon-codeBootcamps
Career Kickstarter
6 Months
Best Seller
Full-Stack Developer BootcampJob Oriented
3 Months
Best Seller
UI/UX Design BootcampEnterprise Recommended
6 Months
Java Full Stack Developer BootcampCareer Kickstarter
490+ Hours
Front-End Development BootcampCareer Accelerator
4 Months
Backend Development Bootcamp (Node JS)Skills
ReactOn-Demand Courses
Angular TrainingTop Resources
Top HTML ProjectsBlockchain
Understand how transactions and databases work in blockchain technology.
View All Blockchain Coursesicon-stop-squareBlockchain Certifications
40 Hours
Blockchain Professional Certification32 Hours
Blockchain Solutions Architect Certification32 Hours
Blockchain Security Engineer Certification24 Hours
Blockchain Quality Engineer Certification5+ Hours
Blockchain 101 CertificationOn-Demand Courses
NFT Essentials 101: A Beginner's GuideTop Resources
Blockchain Interview QsProgramming
Learn to code efficiently and design software that solves problems.
View All Programming Coursesicon-codeSkills
Python CertificationInterview Prep
Career Accelerator
3 Months
Software Engineer Interview PrepOn-Demand Courses
Data Structures and Algorithms with JavaScriptTop Resources
Python TutorialThe LinkedList Collection represents a doubly linked list. It allows insertion, deletion and other operations from the linked list. This collection is found in System.Collections.Generic namespace.
The different constructors and their description is given as follows:
Constructors | Description |
|---|---|
LinkedList<T>() | This constructor initializes a new instance of the LinkedList<T> class that is empty. |
LinkedList<T>(IEnumerable<T>) | This constructor initializes a new instance of the LinkedList<T> class that contains elements copied from the specified IEnumerable and has sufficient capacity to accommodate the number of elements copied. |
LinkedList<T>(SerializationInfo, StreamingContext) | This constructor initializes a new instance of the LinkedList<T> class that is serializable with the specified SerializationInfo and StreamingContext. |
Table: Constructors in LinkedList Collection in C#
Source: MSDN
The different properties and their description is given as follows:
Properties | Description |
|---|---|
Count | This property gets the number of nodes actually contained in the LinkedList<T>. |
First | This property gets the first node of the LinkedList<T>. |
Last | This property gets the last node of the LinkedList<T>. |
Table: Properties in LinkedList Collection in C#
Source: MSDN
The different methods and their description is given as follows:
Methods | Description |
|---|---|
AddAfter(LinkedListNode<T>, LinkedListNode<T>) | This method adds the specified new node after the specified existing node in the LinkedList<T>. |
AddAfter(LinkedListNode<T>, T) | This method adds a new node containing the specified value after the specified existing node in the LinkedList<T>. |
AddBefore(LinkedListNode<T>, LinkedListNode<T>) | This method adds the specified new node before the specified existing node in the LinkedList<T>. |
AddBefore(LinkedListNode<T>, T) | This method adds a new node containing the specified value before the specified existing node in the LinkedList<T>. |
AddFirst(LinkedListNode<T>) | This method adds the specified new node at the start of the LinkedList<T>. |
AddFirst(T) | This method adds a new node containing the specified value at the start of the LinkedList<T>. |
AddLast(LinkedListNode<T>) | This method adds the specified new node at the end of the LinkedList<T>. |
AddLast(T) | This method adds a new node containing the specified value at the end of the LinkedList<T>. |
Clear() | This method removes all the nodes from the LinkedList<T>. |
Contains(T) | This method determines whether a value is in the LinkedList<T>. |
Equals(Object) | This method determines whether the specified object is equal to the current object. |
Find(T) | This method finds the first node that contains the specified value. |
FindLast(T) | This method finds the last node that contains the specified value. |
GetHashCode() | This method serves as the default hash function. |
Remove(LinkedListNode<T>) | This method removes the specified node from the LinkedList<T>. |
Remove(T) | This method removes the first occurrence of the specified value from the LinkedList<T>. |
RemoveFirst() | This method removes the node at the start of the LinkedList<T>. |
RemoveLast() | This method removes the node at the end of the LinkedList<T>. |
ToString() | This method returns a string that represents the current object. |
Table: Methods in LinkedList Collection in C#
Source: MSDN
Before beginning with the Linked List operations, let us first see how to create a simple Linked List:
using System;
using System.Collections.Generic;
class Example
{
static void Main()
{
string [] empID = {"E0001","E0005","E0006"};
Console.WriteLine("Displaying elements of a Linked List: ");
LinkedList<string> myList = new LinkedList<string>(empID);
foreach (var res in myList)
{
Console.WriteLine(res);
}
}
}
Source Code: Program to create a Linked List in C#
The output of the above program is as follows:
Displaying elements of a Linked List:
E0001
E0005
E0006
Some of the Linked List operations are given as follows:
An element is added to the start of the Linked List using the AddFirst() method. Similarly, the AddLast() method can be used to add the element to the end of the linked list. The program that demonstrates this is given as follows:
using System;
using System.Collections.Generic;
namespace LinkedListDemo
{
class Example
{
static void Main(string[] args)
{
LinkedList <int> L = new LinkedList<int>();
L.AddFirst(5);
L.AddFirst(2);
L.AddFirst(8);
L.AddLast(4);
L.AddLast(9);
L.AddLast(1);
Console.Write("Linked List elements are: ");
foreach (int i in L)
{
Console.Write(i + " ");
}
}
}
}
Source Code: Program to add elements in Linked List in C#
The output of the above program is as follows:
Linked List elements are: 8 2 5 4 9 1
An element can be deleted from the start of the Linked List using the RemoveFirst() method. Similarly, the RemoveLast() method can be used to delete the element from the end of the linked list. The program that demonstrates this is given as follows:
using System;
using System.Collections.Generic;
namespace LinkedListDemo
{
class Example
{
static void Main(string[] args)
{
LinkedList <int> L = new LinkedList<int>();
L.AddFirst(5);
L.AddFirst(2);
L.AddFirst(8);
L.AddLast(4);
L.AddLast(9);
L.AddLast(1);
Console.Write("Original Linked List: ");
foreach (int i in L)
{
Console.Write(i + " ");
}
L.RemoveFirst();
L.RemoveLast();
Console.WriteLine();
Console.Write("Linked List after deletion: ");
foreach (int i in L)
{
Console.Write(i + " ");
}
}
}
}
Source Code: Program to delete elements from Linked List in C#
The output of the above program is as follows:
Original Linked List: 8 2 5 4 9 1
Linked List after deletion: 2 5 4 9
The Contains method finds if an element is present in Linked List or not. If it is present, Contains() returns TRUE and otherwise it returns FALSE.
The program that demonstrates this is given as follows:
using System;
using System.Collections.Generic;
namespace LinkedListDemo
{
class Example
{
static void Main(string[] args)
{
LinkedList <int> list = new LinkedList<int>();
list.AddLast(4);
list.AddLast(9);
list.AddLast(1);
list.AddLast(3);
list.AddLast(6);
list.AddLast(2);
Console.Write("Linked List: ");
foreach (int i in list )
{
Console.Write(i + " ");
}
Console.WriteLine();
Console.WriteLine("The value 3 is present in Linked List: " + list.Contains(3));
Console.WriteLine("The value 5 is present in Linked List: " + list.Contains(5));
}
}
}
Source Code: Program to find an element in Linked List in C#
The output of the above program is as follows:
Linked List: 4 9 1 3 6 2
The value 3 is present in Linked List: True
The value 5 is present in Linked List: False
Use the AddFirst() method to add a node at the first position in a Linked List. Let us see how:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Smartphones","Smartwatches"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
myList.AddFirst("Calculators");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Source Code: Program to add a node at the first position in a Linked List in C#
The output of the above program is as follows:
Smartphones
Smartwatches
New list...
Calculators
Smartphones
Smartwatches
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Smartphones","Smartwatches"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
myList.AddFirst("Calculators");
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
myList.AddLast("PDAs");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Use the AddLast() method to add a node at the last position in a Linked List. Let us see how:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Smartphones","Smartwatches"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
myList.AddFirst("Calculators");
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
myList.AddLast("PDAs");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Source Code: Program to add a node at the last position in a Linked List in C#
The above program gives the following output:
Smartphones
Smartwatches
New list...
Calculators
Smartphones
Smartwatches
New list...
Calculators
Smartphones
Smartwatches
PDAs
If you want to add a node after the given node, use the AddAfter() method. Let us see an example:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Smartphones","Smartwatches"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
var n = myList.AddFirst("Calculators");
myList.AddAfter(n, "PDAs");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Source Code: Program to add a node after the given node in a Linked List in C#
The output of the above program is as follows:
Smartphones
Smartwatches
New list...
Calculators
PDAs
Smartphones
Smartwatches
If you want to add a node before the given node, use the AddBefore() method. Let us see an example:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Smartphones","Smartwatches"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
var n = myList.AddFirst("Calculators");
myList.AddBefore(n, "PDAs");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Source Code: Program to add a node before the given node in a Linked List in C#
The above program gives the following output:
Smartphones
Smartwatches
New list...
PDAs
Calculators
Smartphones
Smartwatches
To check whether a node is in a Linked List or not, the best way is to use the Contains() method:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Smartphones","Smartwatches"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("Smartphones in the list?: "+myList.Contains("Smartphones"));
}
}
Source Code: Program to check whether a node is in a Linked List or not in C#
The output of the given program:
Smartphones
Smartwatches
Smartphones in the list?: True
Use the Remove() method to remove the first occurrence of a node. Let us see an example:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Smartphones","Smartwatches"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
var n = myList.AddFirst("Calculators");
myList.AddBefore(n, "PDAs");
foreach (var d in myList)
{
Console.WriteLine(d);
}
myList.Remove("Smartwatches");
Console.WriteLine("\nNew list after removing an element...");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Source Code: Program to remove the first occurrence of a node in C#
The above program gives the following output:
Smartphones
Smartwatches
New list...
PDAs
Calculators
Smartphones
Smartwatches
New list after removing an element...
PDAs
Calculators
Smartphones
Use the RemoveLast() method to remove a node at the end of the Linked List.
The following is an example:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Smartphones","Smartwatches", "Laptop"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
var n = myList.AddFirst("Calculators");
myList.AddBefore(n, "PDAs");
foreach (var d in myList)
{
Console.WriteLine(d);
}
myList.RemoveLast();
Console.WriteLine("\nNew list after removing the last element...");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Source Code: Program to remove a node at the end of the Linked List in C#
The above program gives the following output:
Smartphones
Smartwatches
Laptop
New list...
PDAs
Calculators
Smartphones
Smartwatches
Laptop
New list after removing the last element...
PDAs
Calculators
Smartphones
Smartwatches
Use the RemoveFirst() method to remove a node at the beginning of a Linked List. The following is an example demonstrating the same:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Monitors","Headphones", "Laptop"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
Console.WriteLine("\nNew list...");
var n = myList.AddFirst("Printer");
myList.AddBefore(n, "PDAs");
foreach (var d in myList)
{
Console.WriteLine(d);
}
myList.RemoveFirst();
Console.WriteLine("\nNew list after removing the first node...");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Source Code: Program to remove a node at the beginning of the Linked List in C#
The above program gives the following output:
Monitors
Headphones
Laptop
New list...
PDAs
Printer
Monitors
Headphones
Laptop
New list after removing the first node...
Printer
Monitors
Headphones
Laptop
To clear a Linked List, use the Clear() method. Let us see an example:
using System;
using System.Collections.Generic;
class Demo
{
static void Main()
{
string [] devices = {"Monitors","Headphones", "Laptop"};
LinkedList<string> myList = new LinkedList<string>(devices);
foreach (var d in myList)
{
Console.WriteLine(d);
}
myList.Clear();
Console.WriteLine("\nLinked List cleared...");
Console.WriteLine("\nNew list...");
var n = myList.AddFirst("Printer");
myList.AddBefore(n, "PDAs");
foreach (var d in myList)
{
Console.WriteLine(d);
}
}
}
Source Code: Program to clear a Linked List in C#
The above program gives the following output:
Monitors
Headphones
Laptop
Linked List cleared...
New list...
PDAs
Printer