www.digitalmars.com         C & C++   DMDScript  

D - binary tree?

reply Fabian <Fabian_member pathlink.com> writes:
hrmm can i make a binary tree with D?
seems it doesnt like having a pointer to a class inside a class?

eg:

Node
{
Node pointer;
}

is this possible yet with D?
Apr 20 2004
next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Fabian wrote:

 hrmm can i make a binary tree with D?
 seems it doesnt like having a pointer to a class inside a class?
 
 eg:
 
 Node
 {
 Node pointer;
 }

Have you written a complete program that shows how it doesn't like this yet? Have you tried compiling it yet? Have you come up with an exact error message yet?
 is this possible yet with D?

Yes, as far as I know. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Apr 20 2004
prev sibling next sibling parent "C. Sauls" <ibisbasenji yahoo.com> writes:
I've used this... for example, some code from a database converter I 
semi-recently wrote:

------------------------------
// . . . some junk
class DBObj {
     // . . . some junk

     DBObj    parent,
              children,
              children_next,
              location,
              contents,
              contents_next;

     // . . . some junk
}
------------------------------

So I must not understand what the problem is...

-C. Sauls
-Invironz

Fabian wrote:
 hrmm can i make a binary tree with D?
 seems it doesnt like having a pointer to a class inside a class?
 
 eg:
 
 Node
 {
 Node pointer;
 }
 
 is this possible yet with D?

Apr 20 2004
prev sibling parent reply Stephan Wienczny <wienczny web.de> writes:
Fabian wrote:
 hrmm can i make a binary tree with D?
 seems it doesnt like having a pointer to a class inside a class?
 
 eg:
 
 Node
 {
 Node pointer;
 }
 
 is this possible yet with D?
 
 

What you are trying is _NOT_ possible. "Node" should be "class Node" or "struct Node" Then it should work Have a look at my dlinked list at http://d.wienczny.de
Apr 20 2004
parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Huh?  I do see a minor syntax error...but the code is basically valid. 
You can do this:

class Node {
	Node pointer; // this is a reference to a class object
};

or this:

struct Node {
	Node *pointer;
};

Russ

Stephan Wienczny wrote:
 Fabian wrote:
 
 hrmm can i make a binary tree with D?
 seems it doesnt like having a pointer to a class inside a class?

 eg:

 Node
 {
 Node pointer;
 }

 is this possible yet with D?

What you are trying is _NOT_ possible. "Node" should be "class Node" or "struct Node" Then it should work Have a look at my dlinked list at http://d.wienczny.de

Apr 20 2004