C# OOP: doubly linked list

Element of doubly linked list

Step 1: Define element and operations of the doubly linked list

The doubly linked list element has tree parts--previous pointer or link, data, and next pointer or next link. Therefore, we define the the element of the doubly linked list by using a structure that has three members--data and two pointers.

doubly linked list in C#

//C#(Csharp) code to define list element

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

The operations of the doubly linked list are outlined as the methods in abstract class Cls shown below:

 abstract class Cls<T>
  public void insert(T val, int pos) { }
  public void delete(int pos) { }
  public void printlist() { }
  public ListNode<T> findmin() { return null; }
  public ListNode<T> findmax() { return null; }
  public ListNode<T> find() { return null; }


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.