C # Data structure-bidirectional linked list

Source: Internet
Author: User

Theoretical basis:

In the node set two reference fields, a save the address of the direct predecessor node, called Prev, a direct successor node address, called Next, such a linked list is a two-way list (doubly linked list).

The diagram of the node structure of the bidirectional linked list as above, the definition of the bidirectional linked list node is very similar to the definition of the node of the single linked list, so the realization of the bidirectional linked list nodes class can refer to the node class of the single linked list.

C # implementation:

1 interface

Interfaces referencing a linear table ilistds<t>

2 implementation

(1) Bidirectional linked list node class, reference single linked list node class

Code

[Copy to Clipboard]

CODE:

1  public class DBNode<T>
2  {
3   private T data;       //数据域
4    private DBNode<T> next;    //后继
5    private DBNode<T> prev;    //前驱
6    public T Data
7    {
8      get { return data; }
9      set { data = value; }
10    }
11    public DBNode<T> Next
12    {
13      get { return next; }
14      set { next = value; }
15    }
16    public DBNode<T> Prev
17    {
18      get { return prev; }
19      set { prev = value; }
20    }
21    public DBNode()
22    {
23      data = default(T);
24      prev = null;
25      next = null;
26    }
27    public DBNode(T val)
28    {
29      data = val;
30      next = null;
31      prev = null;
32    }
33  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.