Help to insert the ancestor into each structure correctly.
http://codepad.org/Ynjz6G3L
In the add_tree and create_tree functions.
1 answer
Delov something! head->left->predok=head; and accordingly head->right->predok=head; . And of course phead->predok=NULL; .
And by the way, not predok , but parent .
You'd better draw the squares with the arrows, the problem is elementary.
- @stupidmonkey: Yes, that's right. And what does “not working” mean? The code is correct. - VladD
- In principle, in maine in this line cout << search (phead, key) -> predok -> key << endl; first find by key, then by this key I deduce ancestor. But the program crashes. cs622823.vk.me/v622823450/330d/8jPtDCZr3-I.jpg - stupidmonkey
- @stupidmonkey: Well, yes, your puncture. The root has no ancestor. And function, probably, a root finds. - VladD
- one@stupidmonkey: Here is your code: search (temp-> left, key); And what happens to the value returned from the
search? (Hint: nothing, it is stupidly ignored .) - VladD
|