The chain storage of a linear table is called a linked list. Features: the non-continuous and non-sequential Storage Structure on the storage unit. The logical sequence of data elements is achieved through the pointer link sequence in the linked list.
A linked list consists of a series of nodes (each element in a linked list is called a node), which can be dynamically generated at runtime. Each node consists of two parts: one is to store data elements
The other is the pointer field that stores the next node address.
Linked lists include single-chain tables and two-way linked lists.
The following describes how to implement a single-chain table:
Public Class Node < T >
{
Private T data;
Private Node < T > Next;
Public Node (T val, Node < T > P)
{
Data = Val;
Next = P;
}
Public Node (Node < T > P)
{
Next = P;
}
Public Node (T val)
{
Data = Val;
}
Public Node ()
{
Data = Default (T );
Next = Null ;
}
Public T Data
{
Get { Return Data ;}
Set {Data = Value ;}
}
Public Node < T > Next
{
Get { Return Next ;}
Set {Next = Value ;}
}
}
Public Class LinkList < T >
{
Private Node < T > Head;
Public Node < T > Head
{
Get { Return Head ;}
Set {Head = Value ;}
}
Public LinkList ()
{
Head = Null ;
}
Public Int GetLength ()
{<