User forums > Help
Is the result of "printf" and "debug watch" different?
hnust_zhangyehua:
A very important problem that I forget to tell you :'(
This code runs at Visual Stdio is good, in other words, when the code run at the Visual Stdio, its result, on the "printf windows" whether after execute or in the debugging, is same. Moreover, the result of array C in the Visual Stdio is same as the other result when the code is debugging in the codeblocks.
Therefore, I can get a conclusion that codeblocks goes wrong :'(
BlueHazzard:
codeblocks per se does not go wrong, because codeblocks is not a compiler and for this it has nothing to do with your code / your compiled program...
I don't think that in so simple code a compiler bug triggers so i think your code is wrong on one point... I made a quick look, but i didn't find anything critical (beside that you are not deleting Q after a new call)... One thing i can think of is, that cin reads some garbage from the input buffer...
you can try cpp check to analyze your code: http://cppcheck.sourceforge.net/
i have to admit, that your code is not easy to read and to understand...
--- Code: ---void creat(List &T,int e) //build the tree
{
if(!T)
{
LNode *S;
S=new LNode;
S->data=e;
S->lchild=S->rchild=NULL;
T=S;
}
else if(e>T->data)creat(T->rchild,e);
else if(e<T->data)creat(T->lchild,e);
}
--- End code ---
You assign T a new allocated List, but what happens with the old List??? This is for example a memory leak you should avoid. And i think the whole code is full with this... If your code works, it is luck or tolerance of your OS or compiler, but at one point it will blow up... The consequence is (or better can be) that your program works under debug mode but not in release...
sry i can't help more, but this is now out of the scope of this forum, as you don't have a problem with codeblocks, but with the underlying compiler...
raynebc:
That linked list logic looks wrong to me. When you add a link, it correctly sets either the lchild or rchild pointer of the list's current tail, but the other pointer is left at its initialized value of NULL. Unless you ensure both pointers are correctly adjusted every time you append or prefix a link, it will not correctly function as a doubly linked list.
Navigation
[0] Message Index
[*] Previous page
Go to full version