Member-only story
LinkedList in C# with Examples
The LinkedList related to System.Collections.Generic namespace. A LinkedList is a doubly linked list data structure that allows you to store and manipulate a collection of elements. Unlike arrays or lists, a LinkedList doesn’t require contiguous memory and provides efficient insertions and deletions in the middle of the list.
Features with linkedlist in C#:
Creating a LinkedList:
You can use the System.Collections.Generic namespace to work with LinkedList. You can use the following code to create the linkedlist.
Example
using System;
using System.Collections.Generic;
LinkedList<int> linkedfruitprices = new LinkedList<int>();
LinkedList<string> linkedfruitnames = new LinkedList<string>();
Adding Elements:
You can add elements to a LinkedList using the AddLast method to add to the end, or the AddFirst method to add to the beginning of the list:
Example
linkedfruitprices.AddLast(12);
linkedfruitprices.AddLast(16);
linkedfruitprices.AddLast(22);
linkedfruitprices.AddFirst(2);
linkedfruitprices.AddFirst(19);
linkedfruitnames.AddLast("Apple");
linkedfruitnames.AddLast("Mango");
linkedfruitnames.AddLast("Cherry")…