public static void Main()
Console.WriteLine("Singly Linked List");
Random rnd = new Random();
int position = rnd.Next(1,6);
Node singlyLinkedList = new Node();
int data = rnd.Next(10, 100);
singlyLinkedList.data = data;
previous.next = singlyLinkedList;
previous = singlyLinkedList;
SearchInNode(head, numberToSearch);
head = AddNodeToTheFront(head, 10);
head = AddNodeToTheEnd(head, 99);
head = ReverseList(head);
DeleteFirstMatchingNode(head, numberToSearch);
head = AddNodeToTheFront(head, 10);
head = DeleteAllMatchingNode(head, 10);
public static void SearchInNode(Node n, int numberToSearch)
Console.WriteLine("\nSearching - " + numberToSearch.ToString());
if(n.data == numberToSearch){
Console.WriteLine("Found- " + n.data.ToString());
public static void FindMiddleOfNode(Node head)
Console.WriteLine("Find Middle");
Node fastPointer = head.next;
while(fastPointer != null && fastPointer.next != null)
fastPointer = fastPointer.next.next;
slowPointer = slowPointer.next;
Console.WriteLine(slowPointer.data.ToString());
public static void PrintNodeList(Node n)
Console.WriteLine("Print List");
Console.Write(" " + n.data.ToString());
public static Node AddNodeToTheFront(Node head, int newValue)
Console.WriteLine("\nAddNodeToTheFront - " + newValue);
Node newNode = new Node();
public static Node AddNodeToTheEnd(Node head, int newValue)
Console.WriteLine("\nAddNodeToTheEnd - " + newValue);
Node newNode = new Node();
while(current.next != null){
public static Node ReverseList(Node head)
Console.WriteLine("\nReverseList");
public static void DeleteFirstMatchingNode(Node head, int dataToDelete)
Console.WriteLine("\nDeleting Node - " + dataToDelete.ToString());
while(curr != null && curr.data != dataToDelete)
previous.next = curr.next;
public static Node DeleteAllMatchingNode(Node head, int dataToDelete)
Console.WriteLine("\nDeleting Node(s) - " + dataToDelete.ToString());
if(curr.data == dataToDelete)
if(curr.data == dataToDelete)
previous.next = curr.next;