![]() |
|
#1
|
|||
|
|||
printing binary search treeHi,
I have a binary tree constucted based on following node CPP / C++ / C Code:
I can add nodes to the tree and search through the tree. I am sorting based on lastname (last[20] variable in node). I am assuming that my tree is sorted and now I want to print my tree. I tried inorder travesal to print it but not seems to be working for me. I get segmentation fault. Following is GDB output for 3 nodes list. Quote:
Following is the full program code. CPP / C++ / C Code:
Can someone suggest some algorithm to print the BST.? Thanks, |
|||
|
#2
|
|||
|
|||
|
I think I found your problem. Within print_tree(), you call print_tree() again instantly without checking to first make sure you're not sending it a NULL node, so it will essentially go through infinite recursion until it tries to access a node that's not its. So, this worked for me:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
|
Yes, I guess you are right Dr. Evil. I was wondering about the same. Your solution worked. Except I used it in following way to print a sorted tree..
CPP / C++ / C Code:
Thanks for your response. |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using meta tags help in ranking on some search engine | pcx | Search Engine Optimization Forum | 8 | 29-Mar-2005 16:42 |
| Please help! Dynamic binary tree problem | robsmith | C Programming Language | 3 | 15-Mar-2005 22:20 |
| Displaying node attributes in an XML tree display | njp01u | MS Visual C++ / MFC Forum | 2 | 07-Feb-2005 18:42 |
| Search Engine Positioning 101 and 201 "How To" Tips... | 000 | Search Engine Optimization Forum | 0 | 29-May-2003 11:34 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The