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

    ynaInsert:        AddNode := FOwner.Insert(Destination);

  end;

 

  FUpLeft  := AddNode.FUpLeft;

  FUpRight := AddNode.FUpRight;

  FDownRight := AddNode.FDownRight;

 

  if FUpLeft <> nil then FUpLeft.FDownLeft := Self;

  if FUpRight <> nil then FUpRight.FDownRight := Self;

  if FDownRight <> nil then FDownRight.FUpRight := Self;

 

  AddNode.Free;

end;

 

procedure TYuNode.Delete;

begin

  if not FDeleting then

  begin

    FIsRootOfDeleted := True;

    Free;

  end;

end;

 

procedure TYuNode.CutFromTree;

begin

  if Self = FOwner.FFirstNode then

  begin

    FOwner.FFirstNode := GetNextBrother;

    if FOwner.FFirstNode <> nil then

      FOwner.FFirstNode.FUpRight := nil;

    Exit;

  end;

 

  if FDownRight <> nil then //有下一个兄弟

    if FUpRight <> nil then //有上一个兄弟

    begin

      FUpRight.FDownRight := FDownRight;

      FDownRight.FUpRight := FUpRight;

    end

    else                    //直接指向父结点

    begin

      FUpLeft.FDownLeft := FDownRight;

      FDownRight.FUpRight := nil;

      FDownRight.FUpLeft := FUpLeft;

    end

  else

    if FUpRight <> nil then //有上一个兄弟

      FUpRight.FDownRight := nil

    else                    //直接指向父结点

      FUpLeft.FDownLeft := nil;

end;

 

{ TYuTree }

 

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

var

  Node: TYuNode;

begin

  if Brother = nil then

    if FFirstNode = nil then

    begin

      Result := TYuNode.Create(Self);

      FFirstNode := Result;

      Exit;

    end

    else

      Brother := FFirstNode;

 

  Node := Brother.GetLastBrother;

  Result := TYuNode.Create(Self);

  Node.FDownRight := Result;

  Result.FUpRight := Node;

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

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