Einzelnen Beitrag anzeigen

Benutzerbild von sk.Silvia
sk.Silvia

Registriert seit: 8. Feb 2006
Ort: Slovenia
90 Beiträge
 
Delphi 7 Personal
 
#4

Re: Create Binary Tree From Preorder input

  Alt 22. Apr 2006, 14:37
wooow, thats great, youare so claver, thanks a million, i had to modify the code a little bit but without you i wouldnt have a chance

Delphi-Quellcode:
  procedure TBinTree.CreateInorder(aList :TField; aLeft, aRight : Integer; Var aRoot : TBinTree);
  var m:integer;
        begin
        if aLeft>=aRight then aRoot:=TBinTree.Create(aList[aLeft],nil,nil)
                         else
                            begin
                            m:=(aLeft+aRight) div 2;
                            aRoot:=TBinTree.Create(aList[m],nil,nil);

                            if m>aLeft then CreateInorder(aList, aLeft, m-1, aRoot.Left);
                            if m<aRight then CreateInorder(aList, m+1, aRight, aRoot.Right);
                            end;
        end;

Call In Prog ->
BinTree.CreateInorder(TreeInput,Low(TreeInput),High(TreeInput),BinTree);
So ok, this creates a tree from an Inorder input, but lets say we have two inputs Preorder and Postorder, how can i create an tree from them?

i have to use binary tree cause of uni...but thats abit overwork (not neccessary needed to know for school), but iam trying hard to be the best and to know smt. more to be one day so clever as you again thank you

Silvi
  Mit Zitat antworten Zitat