//链表节点
TSingleLinkedNode<T> = class
public
Value: T;
private
m_Next: TSingleLinkedNode<T>;
end;
TMYLinkedNode<T> = class
public
Value: T;
private
m_Prev, m_Next: TMYLinkedNode<T>;
end;
//链表池
TLinkedNodePool = class
protected
m_Nodes: TArray<TObject>;
m_Index: Integer;
m_Capacity: Integer;
m_Stoped: Boolean;
function NewNode: TObject; virtual; abstract;
procedure FreeNode(node: TObject); virtual; abstract;
function GetNode: TObject;
procedure RetNode(node: TObject);
procedure ReSize;
procedure Clear;
public
constructor Create(nCapacity: Integer = 128); virtual;
destructor Destroy; override;
end;
//单向链表
TSingleLinked<T> = class(TLinkedNodePool)
protected
m_Head: TSingleLinkedNode<T>;
m_CurrNode: TSingleLinkedNode<T>;
m_Count: Integer;
function NewNode: TObject; override;
procedure FreeNode(node: TObject); override;
class function Equal(value1, value2: T): Boolean; static;
public
destructor Destroy; override;
procedure Clear;
procedure Add(value: T);
function Delete(value: T; allItem: Boolean = False): TSingleLinkedNode<T>;
function First: TSingleLinkedNode<T>;
function Next: TSingleLinkedNode<T>;
property Count: Integer read m_Count;
end;
//双链表基类
TMYLinkedBase<T> = class(TLinkedNodePool)
protected
m_Head, m_Tail: TMYLinkedNode<T>;
m_CurrNode: TMYLinkedNode<T>;
m_Count: Integer;
function NewNode: TObject; override;
procedure FreeNode(node: TObject); override;
procedure AddT(value: T);
function DeleteT(value: T; allItem: Boolean = False): TMYLinkedNode<T>;
public
constructor Create(nCapacity: Integer = 128); override;
destructor Destroy; override;
procedure Clear;
function DelNode(node: TMYLinkedNode<T>): TMYLinkedNode<T>;
function First: TMY