16,748
社区成员
发帖
与我相关
我的任务
分享
{链表节点类}
TNode<E> = class(TObject)
private
FElement : E; //当前节点中的元素
FNext : TNode<E>; //当前节点的下一个节点
FPrevious : TNode<E>; //当前节点的上一个节点
published
property Element : E read FElement write FElement;
property Next : TNode<E> read FNext write FNext;
property Previous : TNode<E> read FPrevious write FPrevious;
public
constructor Create; overload;
constructor Create(Next : TNode<E>;Previous : TNode<E>);overload;
constructor Create(element : E;Next : TNode<E>;Previous : TNode<E>);overload;
destructor Destroy; override;
end;
{ TNode<E> }
constructor TNode<E>.Create;
begin
inherited;
// 这里怎么写? FElement := ??
FNext := nil;
FPrevious := nil;
end;
constructor TNode<E>.Create(element: E; Next, Previous: TNode<E>);
begin
FElement := element;
FNext := Next;
FPrevious := Previous;
end;
private class Node<E>{
E element;
Node<E> next;
Node<E> previous;
public Node(E element, Node<E> next, Node<E> previous) {
super();
this.element = element;
this.next = next;
this.previous = previous;
}
}