I am looking for assistance with an algorithm to copy even data in a BST of integer data. I have a somewhat working algorithm, but it misses some right nodes, and I don't know what I'm doing wrong.
it looks like you have the right idea. I don't see the issue, but assuming dest is a new tree, and assuming you already have an insert function, ... you are doing too much here. it should literally be
and at the end dest would be a new tree with only the even node data.
Which is close to what you have but you are trying to mudge the inserts and the find and the traversal and everything into one recursive function and likely there is a bug in it.
See if you can get it with a reduced approach and if not I will look harder.
Thank you for the input. I know its atypical/unrealistic and given a better class structure, I don't think it would be as much of a problem, but its for a practice system in university.
The system has just a BST generator (random integer data), a node struct, and a table class (with only default ctor, and inorder display). We are assigned, usually weird, questions to work with that system..
This is a practice question for that system, so we are somewhat restricted on what we can implement.
But I think I will go with that, and just try my luck with the grader. It seems far less complex.
Ok. Some schools seem to delight in making students do things that make no sense.
All I am really saying, if you want to boil it down, is that your function is doing too much and recursion is aggravating to debug. Make it do less by splitting up the problem, is the general idea here, so you can test each piece and find the bugs quickly.
Yeah, the intent (I imagine) is more problem solving. But yeah, some of them are really off the wall and I've gotten berated for trying to get help (stackexchange).
I ended up going with a simple insert function (as you recommended) and everything worked as follows: