本帖最后由 daydream 于 2012-9-19 17:22 编辑 type
PNode = ^TNode;
TNode = record
preNode : PNode;
nextNode : PNode;
ObjData : Tobject;
intIndex : Integer; //用作索引
strIndex : String; //用作索引
end;
TLinkList = class
private
HeadNode : PNode;
HMutex : THandle; //互斥锁,保证在多线程中,不重入
inumber : Integer;
protected
function GetTail : PNode;
public
property Head: PNode read HeadNode; //头结点
property Tail: PNode read GetTail;
property Count : Integer read inumber; //结点个数
//得到前后的结点
function GetNextNode(const node:PNode):PNode;
function GetPreNode(const node:PNode):PNode;
//插入删除结点
procedure AddItem(const Obj:TObject;
const integerIndex:Integer=0;
const stringIndex:string='';
const ToTail:Boolean=true);
function DelItem(node : PNode):Boolean;
//索引结点
function IndexOfInteger(const ivalue : Integer):PNode;
function IndexOfString(const strvalue : String):PNode;
function IndexOfObject(const objvalue : TObject):PNode;
function IsEmpty:Boolean;
procedure Clear;
constructor Create;
destructor Free;
end;
[/code]测试代码var
i : integer;
P : PNode;
begin
list := TLinkList.Create;
i:=3;
list.AddItem(TObject(i));
i:=4;
list.AddItem(TObject(i));
P := list.Head;
list.DelItem(P^.nextNode);
P := list.Head^.nextNode;
while P<>nil do
begin
ShowMessage(IntToStr(Integer(P^.ObjData)));
P :=P^.nextNode;
end;
list.Free;
end;
|