[Gambas-user] Data Structures like C++

tobi tobiasboege01 at ...1601...
Thu May 24 13:34:29 CEST 2012


On Thu, 24 May 2012, Bruce wrote:
> On Thu, 2012-05-24 at 11:07 +0200, tobi wrote:
> 
> > (Completely giving up anything I knew about binary trees now, because it wasn't much and it wasn't
> > even from a book):
> > You said that you can traverse from any node in the tree. 
> No, any node can be considered as a root for a subtree.  Anynode.parent
> provides what I think your saying.
> 
> > Consequently every node has to provide
> > such functionality. 
> (Aside, I think that separating the functionality from the node is the
> key of what I was trying to say. But that is a side issue.)
> 

What I, however, was trying to say is: every node can be the root of a tree and at the same time a
node within another tree, in that point, we already met, right? So there has to be _one_ node class
for the generic node above (that can possess both attributes) that implements methods which
resemble the tree algorithms. That way we could have a basic tree datastructure - if it is that
simple. This basic datastructure can be inherited, overridden, etc.
If the node class is aware of these both attributes (being root node of a tree and itself node in
a tree at the same time) one can easily concatenate trees and that's what I wanted to show with my
code above. (Sorry if I re-invent the wheel here)
What you were out for, if I got you right, was only providing a datastructure for nodes and a
separate class with code to handle them? Like pluggable algorithms on the same structures?

> > I don't deem it necessary to distinguish between root and other nodes. 
> Only in that the "tree" happens to be a directed graph that has one
> special node.  I told you graphs were interesting.
> 
> > The codeis only once there anyway. It could even have helped in your case to "em-parent" (sorry, not a
> > native English speaker) a node that you formerly assumed to be the root like
> > 
> > NewNode.Left = RootNode
> > RootNode = NewNode
> > 
> > As interesting as it sounds, I'm probably not the right person to work on this. I don't have much
> > time for (I don't think so but from a pure conscientiousness point I need to prepare my A-level a
> > bit) and nobody else wants to wait until I finish the theory ;)
> > 
> Having been born some time in the middle of the last century, I have no
> idea what an A-level is.  I hope it's not painful. :-)
> 
> > Regards,
> > Tobi
> 
> and regards from me too!
> 
> But if A-levels are what I think they are, I can recall thinking some 40
> years ago, "calculus, as if I am ever going to need that in my life,
> ha!".
> Wrong.  :-)
> 
> Now get back to those books!
> 
> 

(Hrm, regarding your timezone you must be somewhere near Autralia...) The word can be another one
down there, it is the highest school graduation level here and really far from painful, almost
simplistic. But back to the topic. It would be nice if there was someone to implement that natively.
I'm not going to promise anything but I have a book lying around here with a relatively short
chapter on graphs (and trees) and almost half a week of holidays left... :) If only, it could be
preliminary work to gb.datastructures (even if I find that the name could be improved)

Regards,
Tobi




More information about the User mailing list