![]() |
|
#1
|
|||
|
|||
can anyone help me with my tree :)hi there
I'm new member here and also I'm kindda new user in C++ it's my 1st course in it. I was asked in the college to do a project that allow us to search a text file, and order words in it in des. order using Binary Search Tree... I'd started with it coding 1st my BST with I'll use, so I didn't compelete my task yet, but I need some help with my BST... after coding it and there was no errors at all I'm not able to insert items to my tree using InsertItem function that I'd built the proggrame runs but no item is added, so can anyone check this up and try to help me, I'd be veryyyyyy thankful and here's the code(the class header , the class CPP. and the main ) ************just concentrate on te function InsertItem and its use CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
I've forgot something that I built another InsertItem function but it doesn't work aslo :S here it is : CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
Re: can anyone help me with my tree :)Quote:
Well, for a new user, you have done a lot of work, and the first sign of success is very encouraging: getting the blasted stuff to compile with no errors. That's a Big Step. Now, for the good stuff: Debugging. Since you have a program that executes (even though it does the "wrong thing"), make the program tell you exactly what's happening: where is it going and what is it seeing at each step. The first thing I would do in main() would be to try to find how far it gets: So, my main() might look like this: CPP / C++ / C Code:
(Note that I changed it to comply with the C++ standard: main() is an int type. I eliminated extra #include files, just because I don't like clutter. You do whatever works for you, but I suggest that you get out of the "void main()" habit. Some compilers will simply not accept that, so why do it?) Now, I put a print statement before each function call. That way, I can see if it gets back from one function and calls the next. When the program bombs (and it does for me), I know how far it got. Note that I don't necessarily know that everything before the bomb works OK, but at least I know how far it got. Let's say you get an output like this: Code:
And then the program bombs (or maybe it doesn't bomb, but it doesn't print anything else). Then I feel that the problem is probably in the InsertItem() function. Now what? Well, I instrument the function to see how far it gets there. So, I might change the function to look something like this: CPP / C++ / C Code:
Now, I have put a "progress report" at almost every stinkin' line of the function. In general the function might be too big to put something at every line, so I might choose a strategic subset (before every function call; before statements that dereference pointers). Not everyone works this way, but I suggest that it is very valuable to be able to see how use the program itself to debug the program. I suggest that you can try something like this to see exactly what your program is seeing at each step. Maybe the actual problem was in some previous statement (in some other function) that didn't leave things in correct state for this function to work. If you suspect that then what? Instrument the other stuff to make the program tell you what the heck is going on. Regards, Dave |
|
#3
|
|||
|
|||
Re: can anyone help me with my tree :)thanks very much dave for helping me with my code...
well, I tryed the way that you told me to trace my code and here's the output that I got: Quote:
then it bombs so I am not able figure out where the problem is, because it doesn't even call lengthIs() function so I don't think that the problem is in this function and at the same time it compeletes the calling of InsertItem() so I'm stuck :s |
|
#4
|
|||
|
|||
Re: can anyone help me with my tree :)Quote:
What's the thing that the program does next: CPP / C++ / C Code:
If parentptr is equal to NULL, then dereferencing it is illegal (the statement that uses parentptr->). So, that's surely where it bombs. The question is: how can parentptr be NULL? The program surely expects it to be a pointer to something that can be used here. What part of the program is supposed to set parentptr to something valid. It's like a detective story: you have found a major clue; now you have to collar the murderer. Dave |
|
#5
|
|||
|
|||
Re: can anyone help me with my tree :) |
|
#6
|
|||
|
|||
Re: can anyone help me with my tree :)Quote:
Quote:
As a person who just solved a problem you have absolutely no need to be sorry. Rejoice! Furthermore, if I considered it a bother, I wouldn't keep coming back. Look at it another way: I'm hoping that, by spelling out (in almost painful detail) a logical sequence of tracking down bad behavior, others may also be able to make out a small light at the end of some tunnel. (That's my little fantasy, anyhow.) Regards, Dave |
Recent GIDBlog
Meeting the populace by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Binary Search Tree in C++ | rpg3 | C++ Forum | 5 | 02-Apr-2006 09:53 |
| Binary Search Tree.. | triples1488 | C++ Forum | 7 | 21-Mar-2006 07:16 |
| printing binary search tree | nkhambal | C Programming Language | 2 | 26-Mar-2005 03:01 |
| Displaying node attributes in an XML tree display | njp01u | MS Visual C++ / MFC Forum | 2 | 07-Feb-2005 17:42 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The