need urgent help before submission

hello all,

i've worked on this project for very long time and have dedicated a lot of hours to make it and debug and fix bugs and everything went well. i've had a power outtage and i was sure that i saved the last edit which worked perfectly, but unfortunately, day before my submission due, it turned out that not. insert function is not working properly.

could you please look into it and help me fix it? it's really really important and i would really appreciate help to sort it out.

link to the full project is here: https://onlinegdb.com/HyLSg433 (very convenient and the code can also be compiled here online and changes can be shared easily)

specific code(though i'd be very happy if you could look at my code and give me tips before the final submission)

 


thank you so much and sorry for the sudden rush. i've dedicated so much time for this and because of a power outage everything got messed up :(
Last edited on
If your function has a return type other than void, it always needs to return something.

checkIfTreeIsEmpty, checkIfTreeIsInitialized have no return statements.

checkIfNumOfArguemntsIsThreeOrMore and returnIDThreeArguments only return a proper item under certain conditions -- i.e. there are codepaths that lead to nothing being return (illegal).
Last edited on
is this the only problem? was my logic correct with them? i think there's an error with them that i cannot catch and i don't know what
Last edited on
I don't know what the correct logic is. I'm just looking at the obvious errors. If you want to track down possible logic errors, you should develop test cases for yourself. Develop test cases for yourself with input and expected output so that you know whether or not it's doing the behavior your expect it to.

e.g. If you have a function f(x) = x + 1, and you give it an input of 3, then you expect the output to be 4. Same thing applies here, but it might be "I inserted Y Z X into my tree. Then printing out the tree should give X Y Z" or something like that.

Also, turn on compiler warnings for whatever compiler your use.
Last edited on
Skimming the code I notice that case 5 in main is missing a break.
thanks, doing what you've recommended
Does TNode need a dtor to delete it's dynamically-allocated string? (It could probably use a ctor, too.) And why was that string dynamically allocated anyway? Probably should've just been copied in the normal way. Then it's deletion is automatic, too.
tpb: what you said is very important, but i am not sure i understand it. could you provide a code so i could undestand better?

and if i change the definition of the string from a pointer to normal std::string, do i have to change all of the references and callings in the code?

thank you very much
I see that you specifically delete s_Name before deleting a TNode. So you may have handled it correctly as far as that goes. But if you really needed a dynamic object (with a pointer) then you should give TNode it's own destructor so it can handle deleting s_Name itself and you don't have to worry about it. But in this case s_Name can just be a string and will handle itself. Just make it a string and fix everywhere in the code where it accesses it. For instance you print it out now by dereferencing it, so you would remove that.

In other news, the first bunch of little functions in functionality.cpp are missing return values in the case where the if condition is false. And I think checkIfTreeIsInitialized is returning the wrong value (should return true if it's inititalized). I couldn't get it to run properly until that was fixed.

BTW, in your menu, you say "IN" order, "ON" order, "POST" order.
It's usually "PRE" order, "IN" order, "POST" order.

And it's kind of funny that I have to choose number 1 from the menu for insert and then still have to type the word insert. (And if I forget to type it it segfaults.)

And I would get rid of all the little stub functions in main. They aren't doing any good.
thank you so much! learnt a lot from your comments!
Please DO NOT DELETE YOUR CODE after getting answers. It makes this thread useless as a resource for others to learn fom. It's a selfish abuse of this forum.

Please restore your post.
Topic archived. No new replies allowed.