By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 435,501 Members | 2,817 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

# Structure

 P: n/a I'd like to make a tree without any functions. I mean just using the structure. I have a structure: struct TTree { int key; struct TTree* pLeft; struct TTree* pRight; } Tree[] = { ?????????? } In the place with quastions I should write something for making a tree. (Any tree). I just need to know how is it possible. I wrote something like struct TTree { int key; struct TTree* pLeft; struct TTree* pRight; } Tree[] = { 5, Tree[3], Tree[6], 4, NULL, NULL, 6, NULL, NULL } It didn't work. Nov 13 '05 #1
Share this Question
2 Replies

 P: n/a maths_fan wrote: struct TTree { int key; struct TTree* pLeft; struct TTree* pRight; } Tree[] = { 5, Tree[3], Tree[6], 4, NULL, NULL, 6, NULL, NULL } It didn't work. struct TTree { ... }; static struct TTree node4 = { 4, NULL, NULL }, node6 = { 6, NULL, NULL }; static struct TTree node5 = { 5, &node4, &node6 }; struct TTree *Tree = &node5; This is assuming you want your Tree variable to be a pointer and not the root node itself. I.e. if you want to be able to change which node is the root node. Otherwise you could rename node5 to Tree. -- Hallvard Nov 13 '05 #2

 P: n/a maths_fan wrote: I'd like to make a tree without any functions. I mean just using the structure. I have a structure: struct TTree { int key; struct TTree* pLeft; struct TTree* pRight; } Tree[] = { ?????????? } In the place with quastions I should write something for making a tree. (Any tree). I just need to know how is it possible. I wrote something like struct TTree { int key; struct TTree* pLeft; struct TTree* pRight; } Tree[] = { 5, Tree[3], Tree[6], 4, NULL, NULL, 6, NULL, NULL } It didn't work. Nit picking: How do you print it without any functions? Try this: #include struct TTree { int key; struct TTree* pLeft; struct TTree* pRight; } Tree[] = { /* Tree[0] */ 5, &Tree[1], &Tree[2], /* Tree[1] */ 4, NULL, NULL, /* Tree[2] */ 6, NULL, NULL }; int main(void) { puts("Tree Program"); return 0; } -- Thomas Matthews C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html Other sites: http://www.josuttis.com -- C++ STL Library book Nov 13 '05 #3

### This discussion thread is closed

Replies have been disabled for this discussion.