Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Tree structures?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00168160
Message ID:
00168170
Vues:
23
Jeff,

Here's some code from my PTF-OOP book for building binary trees. It should give you a start:
* tree3f.prg

define class BinaryTree as custom

moLeftChild  = .null.
moRightChild = .null.
muData       = .null.
Name         = "BinaryTree"

protected procedure Init( puData )
this.muData = puData
endproc

procedure Insert( puData )

if ( puData < this.muData )
   if ( IsNull( this.moLeftChild ) )
      this.moLeftChild = createobject( "BinaryTree", puData )
   else
      this.moLeftChild.Insert( puData )
   endif
else
   if( IsNull( this.moRightChild ) )
      this.moRightChild = createobject( "BinaryTree", puData )
   else
      this.moRightChild.Insert( puData )
   endif
endif

endproc


procedure InorderTraverse()

if ( ! IsNull( this.moLeftChild ) )
   this.moLeftChild.InorderTraverse()
endif

?? this.muData, " "

if ( ! IsNull( this.moRightChild ) )
   this.moRightChild.InorderTraverse()
endif

endproc


procedure Destroy()

* postorder traverse to clean up tree

this.moLeftChild = .null.
this.moRightChild = .null.
this.muData = .null.
endproc

enddefine
>Im wondering how one would implement a set of records that are sorted tree like, as oposed to linearly. ie create a family tree where each node can have a marrage link, more than one children link, and a parent link. Not a simple tree, either: there would actualy have to be more that one marrage link, and maried into the family people would only have one link.
>
>Any idea how one would do this, indeed, is it possible?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform