C# OOP: Singly Linked List

Element of singly linked list

Step 1: Define element of the singly linked list

The linked list element has two parts--data and a link. Therefore, we define the the element of the linked list by using a class that has two members--data and next link.

C single linked list

//C# code to define list element

//List element class
class ListNode<T> //T is the generic type.
{
public ListNode(T elem) { val = elem;next = null; }
public T val; //element data
public ListNode<T> next;//next link
}




Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.