# Delete node from linked list with specific value

In computer science, a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence

In this article, I will show you how to delete nodes from Linked List. The question can be asked in several ways like delete a node from given linked list or delete a linked list node at specific position in c#.The Algorithm for deleting the node from the linked list is shown below

## Algorithm

``````While i<index-1
pre=prev.Next
nodeToDeleted=prev.next;
prev.next=nodeToDeleted.next
``````
• Set `prev` pointer to `head`
• Loop till `position-1`
• Get the next node from the `prev`
• Set the `prev` next to a node to be deleted node.

]

``````void Main()
{
}
``````
``````public class LinkedList
{

private class Node
{
public int Data { get; set; }
public Node Next { get; set; }
public Node(int data)
{
Data = data;
Next = null;

}
}

public void Insert(int data)
{

var newNode = new Node(data);
{
return;
}
else
{
}
}
// To Print the string
public override string ToString()
{
var builder = new StringBuilder();
while (current != null)
{
builder.Append(current.Data + "->");
current = current.Next;
}
builder.Append("NULL");
return builder.ToString();
}

public void RemoveNode(int index)
{

//If LL is empty do nothing
return;

if (index == 0)

for (int i = 1; i < index - 1; i++)
{
prev = prev.Next;
}
var nodeToBeDeleted = prev.Next;
prev.Next = nodeToBeDeleted.Next;

}

}
``````