Q:
C# program to delete a given node from the singly Linked-List
belongs to collection: C# Data Structure Solved Programs/Examples
C# Data Structure Solved Programs/Examples
- C# program to implement stack using array
- C# program to implement stack using structure
- C# program to implement Double Stack using structure
- C# program to implement Double Stack using class
- C# program to implement linear queue using array
- C# program to implement Linear Queue using structure
- C# program to implement circular queue using array
- C# program to push elements to stack using collection
- C# program to pop elements from stack using collection
- C# program to check whether element exists in stack or not
- C# program to copy stack elements to array
- C# program to insert or enqueue elements into queue using collection
- C# program to delete or dequeue elements from queue using collection
- C# program to clear all elements of Queue
- C# program to count total items/elements of Queue
- C# program to check element is exist in Queue or not
- C# program to copy Queue elements to array
- C# program to convert queue into object array
- C# program to peek elements from Queue using collection
- C# program to get all stack frames using StackTrace class
- C# program to implement Post-order traversal in Binary Tree
- C# program to implement Pre-order traversal in Binary Tree
- C# program to implement In-order traversal in Binary Tree
- C# program to traverse the singly linked list
- C# program to delete a given node from the singly Linked-List
- C# program to demonstrate the Tower Of Hanoi
- C# program to implement selection Sort
- C# program to implement selection Sort to arrange elements in the descending order
- C# program to sort an array in ascending order using insertion sort
- C# program to sort an array in descending order using insertion sort
- C# program to sort an array in ascending order using bubble sort
- C# program to sort an array in descending order using bubble sort
- C# program to sort an array using quick sort
- C# program to sort an array using merge sort
- C# program to sort an integer array using Radix Sort
- C# program to implement the Heap Sort
Program:
The source code to delete a given node from the single linked list is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a ListNode class that contains data member's item and next. As we know that the node of a linked list contains item and pointer to the next node.
The ListNode class contains two constructors, AddItem(), ListTraverse(), and DeleteNode() methods. The AddItem method is used to add items into the node that it will return the address of the node.
The ListTraverse() method is used to traverse the list from the start node to the end of the node in the linked list.
The DeleteNode() method is used to delete a given specified node from the linked list.
Now look to the Demo class that contains the Main() method. Here, we created the nodes using ListNode class and then add items and link the node to make a Linked List. After that we finally traverse the list from start to end and printed the items on the console screen after that we deleted the node n2 from the list and printed the updated list on the console screen.