打印本文 打印本文 关闭窗口 关闭窗口
自己编写树(Tree)的封装类
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4966  更新时间:2009/4/23 18:34:19  文章录入:mintao  责任编辑:mintao
end;

 

function TYuTree.AddChild(Parent: TYuNode): TYuNode;

var

  Node: TYuNode;

begin

  if Parent = nil then

  begin

    Result := Add(nil);

    Exit;

  end;

 

  Node := Parent.GetLastChild;

  Result := TYuNode.Create(Self);

 

  if Node = nil then

  begin

    Parent.FDownLeft := Result;

    Result.FUpLeft := Parent;

  end

  else

  begin

    Node.FDownRight := Result;

    Result.FUpRight := Node;

  end;

end;

 

function TYuTree.AddChildFirst(Parent: TYuNode): TYuNode;

var

  Node: TYuNode;

begin

  if Parent = nil then

  begin

    Result := Add(nil);

    Exit;

  end;

 

  Node := Parent.GetFirstChild;

  Result := TYuNode.Create(Self);

 

  if Node <> nil then

  begin

    Node.FUpLeft := nil;

    Node.FUpRight := Result;

  end;

 

  Result.FUpLeft := Parent;

  Result.FDownRight := Node;

 

  Parent.FDownLeft := Result;

end;

 

function TYuTree.AddFirst(Brother: TYuNode): TYuNode;

var

  Node, Parent: TYuNode;

begin

  if Brother = nil then

  begin

    Result := Add(nil);

    Exit;

  end;

 

  Node := Brother.GetFirstBrother;

  Parent := Node.Parent;

  Result := TYuNode.Create(Self);

 

  Node.FUpLeft := nil;

  Node.FUpRight := Result;

 

  Result.FUpLeft := Parent;

  Result.FDownRight := Node;

 

  if Parent <> nil then

    Parent.FDownLeft := Result

  else

    FFirstNode := Result;

end;

 

procedure TYuTree.Clear;

begin

  while FFirstNode <> nil do

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9]  下一页

打印本文 打印本文 关闭窗口 关闭窗口