Introduction
In this blog, we are discussing the linked list concepts with simple programs.
The linked list is an abstract data type that represents the family of data structures where data structures represent a linear and sequential way.
- Please check the below snapshot:
We can see in the above snapshot A, B, C, that these are nodes. A node has two elements, data, and pointer. A pointer points towards to the next node. A points towards B and B points towards C.
We have 3 types of linked lists:
- Simple linked list: We have a node and the node points towards the next node. Here we have a one-way pointer.
- Double linked list: Node points towards the next node, also it will point to the previous node.
- Circular linked list: Every node will point towards the next node and also the last node points to the first node.
Let's create a simple linked list.
Step 1
First, create a simple console application.
Step 2
First, we need to create one node. Please create one class and name it as a node. This class has two properties, one is data and another one is the pointer.
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace LinkedList
- {
- public class Node
- {
- object data = null;
- Node next = null;
- }
- }
We need to create one more class which holds the logic of the linked list concepts. Let's create AddFirst, AddLast, ReadAll methods.
In the AddFirst method, it will add data before the current head. First, we need to create the first item and we want this as our first item so we need to set items as the head.
- public void AddFirst(object data)
- {
- Node newitem = new Node();
- newitem.data = data;
- newitem.next = head;
- newitem = head;
- }
In the AddLast method, we are creating the last node. Loop and find the last node and if it is null this means this is the last element to the current next set new item.

Join the conversation! Your thoughts help the community grow.