{linked list node class}
TNode=class (TObject)
Private
FElement: E;//the elements in the current node
FNext: TNode;//the next node of the current node
FPrevious: TNode;//of the current node in a node
Published
The property Element: E read FElement write FElement;
The property Next: TNodeRead FNext write FNext;
The property Previous: TNodeRead FPrevious write FPrevious;
Public
The constructor Create; The phrase ";
The constructor Create (Next: TNode; Previous: TNode The constructor Create (element: E; Next: TNode ; Previous: TNode The destructor Destroy; Override.
end;
I want to write a two-way linked list, this is the node class,
{TNode}
The constructor TNode. Create;
The begin
Inherited;
//how to write here? FElement:=??
FNext:=nil;
FPrevious:=nil;
end;
The constructor TNodeThe Create (element: E; Next, Previous: TNode The begin
FElement:=element;
FNext:=Next;
FPrevious:=Previous;
end;
1. The two overloaded methods, below the TNode
2. Also, the first in the Create method FElement there how to write? What is the difference between a null and nil?
I know that in Java are assigned to null, Delphi consult

Private class Node{
E element;
NodeNext;
NodePrevious;
Public Node (E element, NodeNext, Node Previous) {
Super ();
Enclosing element=element;
This. Next=next;
This. Previous=previous;
}
}
CodePudding user response:
TryType
TNode
Strict private//digression: add keyword best strict, strict private members can be similar to c + + friend yuan feature is invalid,
//Delphi with a unit within the classes of the existence of private members are actual friend yuan
.
The constructor TNode
The begin
FElement:=nil;//can be assigned nil
FNext:=nil;
FPrevious:=nil;
end;
You directly to generics. The best collections in the unit to find a suitable list class inheritance, for example TStack
An all over for a long time did not use d2009 version, generics are not necessary, no chance to get big project, also can't realize the benefits of generics to improve work efficiency, I will use less are not familiar with,
I only know that in other Delphi variants in the unit has a Null function, Null () function returns a Null variant,
Keyword null is not clear, looks like at the beginning of the d6 null keyword was abandoned,
CodePudding user response: