I think the problem is these lines:
if (Bnode != NULL) {
abc.addQ (Bnode - data);
prefix_trav (abc, Bnode-leftChild);
prefix_trav (abc, Bnode-rightChild);
}
return abc;
You're traversing the left and right children, however this doesn't affect abc
. What you should try is this:
if (Bnode != NULL) {
abc.addQ (Bnode - data);
abc = prefix_trav (abc, Bnode-leftChild);
abc = prefix_trav (abc, Bnode-rightChild);
}
return abc;
But also, I notice you have Bnode-leftChild
and Bnode-rightChild
. This looks like a pointer subtraction to me - is this your intention? Should you be using ->
instead of -
?