![]() |
|
#1
|
|||
|
|||
Please help! Dynamic binary tree problemHi I am a new C programmer and have produced a program which reads in a file and prints it out. I now need to produce a dynamically built binary tree data structure to hold results.
The program should read the data for a competitor, place this in a new structure (using memory space acquired using malloc() or calloc()) and then insert this new structure in the appropriate place within the dynamically built binary tree of structures. I am quite baffled and not sure where to start Any ideas would be greatly appreciated x Here is the code so far: CPP / C++ / C Code:
CPP / C++ / C Code:
Here is the text file containing the competitor details and results: Spring Fishing. 14th April 2005. Margaret Mouse Skirting Board House, Mosehole, Devon. DV1 2SS Southern 9365 1 0 1 2 7 13 0 4 5 Bert Hill 14, Priory Lane, Birmingham, West Midlands. B19 1RU Central 2000 0 12 9 1 11 5 1 10 4 Donald Duck Village Pond, Duckington-by-Sea. S11 1QQ Marine 123456 1 13 10 4 7 15 2 5 7 Last edited by LuciWiz : 15-Mar-2005 at 09:43.
Reason: Please insert your C code between [c] & [/c] tags
|
|||
|
#2
|
||||
|
||||
|
Hello robsmith. Do you remember the band the cure? You probably get that alot though.
Anyway, you are probably familiar with a tree structure, but it helps to review it in order to create it. You should start with a data structure that has pointers to left and right branches. If you want to traverse backwards through a tree, you could add a root node as well, but this is not really necessary. CPP / C++ / C Code:
You probably want to define a local variable for your root node and also set it to 0 so you know if your tree contains any data or not. CPP / C++ / C Code:
When you add data, you should allocate the memory for it as well as copy in the data that it will contain CPP / C++ / C Code:
Then your insert node function should parse to the proper location and insert the node. CPP / C++ / C Code:
That should get you started. That is 100% untested off of the top of my head, but hopefully it can point you in the right direction. Also, if you know how to do recursion, it works really well for a tree like structure. Good luck! __________________
The best damn Sports Blog period. |
|
#3
|
|||
|
|||
ThanksHi, thanks for all your help, it was extremely kind of you :-D
I'll try it out ASAP. No i dont remember a band called the cure sorry, was there a rob smith? |
|
#4
|
|||
|
|||
|
Quote:
HAHa lol ... you must be joking?? or I am feeling old lol The cure was an 80's band that sucked and their singers name was Rob Smith :-P |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Displaying node attributes in an XML tree display | njp01u | MS Visual C++ / MFC Forum | 2 | 07-Feb-2005 18:42 |
| problem reading to a dynamic array | noamfrie | C Programming Language | 9 | 02-Jan-2005 19:35 |
| Binary Tree Trouble | neufunk | C Programming Language | 4 | 06-Dec-2004 10:52 |
| tree problem | zuzupus | MySQL / PHP Forum | 0 | 01-Aug-2003 09:27 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The