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

 

  //3.如果第2步不成功,查看父结点的下一个兄弟

  //退出条件,成功找到(Result <> nil) 或 直到根结点仍没有找到(Node = nil)

  Node := Self.Parent;

  while (Result = nil) and (Node <> nil)  do

  begin

    Result := Node.GetNextBrother;

    Node := Node.Parent;

  end;

end;

 

function TYuNode.GetNextBrother: TYuNode;

begin

  Result := FDownRight;

end;

 

function TYuNode.GetParent: TYuNode;

begin

  Result := GetFirstBrother.FUpLeft;

end;

 

function TYuNode.GetPrev: TYuNode;

var

  Node: TYuNode;

begin

  //1.得到上一个兄弟

  Node := GetPrevBrother;

 

  //如果没有上一个兄弟,返回父结点

  if Node = nil then

  begin

    Result := Self.Parent;

    Exit;

  end;

 

  //否则,返回PrevBrother.GetLastChild.GetLastChild.........

  Result := Node;

  while Node <> nil do

  begin

    Result := Node;

    Node := Node.GetLastChild;

  end;

end;

 

function TYuNode.GetPrevBrother: TYuNode;

begin

  Result := FUpRight;

end;

 

procedure TYuNode.MoveTo(Destination: TYuNode; Mode: TYuNodeAttachMode);

var

  DestParent, AddNode: TYuNode;

begin

  if Destination = nil then

  begin

    Delete;

    Exit;

  end;

 

  if Destination.FOwner <> FOwner then

    raise Exception.CreateFmt(''''YuNode[@%d] Move To Another Tree In TYuNode.MoveTo'''', [Integer(@Self)]);

 

  DestParent := Destination.Parent;

  while DestParent <> nil do

  begin

    if DestParent = Self then

      raise Exception.CreateFmt(''''Destination Is YuNode[@%d]''''''''s SubNode In TYuNode.MoveTo'''', [Integer(@Self)]);

    DestParent := DestParent.Parent;

  end;

 

  CutFromTree;

  case Mode of

    ynaAdd:           AddNode := FOwner.Add(Destination);

    ynaAddFirst:      AddNode := FOwner.AddFirst(Destination);

    ynaAddChild:      AddNode := FOwner.AddChild(Destination);

  

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

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