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 }