You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The book text, as well as the Java and Python implementations, all use Queues to accumulate nodes to visit, but in the C++ code, the supporting data structure is ArrayDeque<Node*>. Elements are added at q.size() but instead of being removed at the other end, they're removed at q.size()-1. (See full implementation pasted in below.)
This strikes me as odd; I'm happy to submit a PR to fix this, but I wanted to check that I'm not overlooking something.
void BinaryTree<Node>::bfTraverse() {
ArrayDeque<Node*> q;
if (r != nil) q.add(q.size(),r);
while (q.size() > 0) {
Node *u = q.remove(q.size()-1);
if (u->left != nil) q.add(q.size(),u->left);
if (u->right != nil) q.add(q.size(),u->right);
}
}
The text was updated successfully, but these errors were encountered:
The book text, as well as the Java and Python implementations, all use Queues to accumulate nodes to visit, but in the C++ code, the supporting data structure is
ArrayDeque<Node*>
. Elements are added atq.size()
but instead of being removed at the other end, they're removed atq.size()-1
. (See full implementation pasted in below.)This strikes me as odd; I'm happy to submit a PR to fix this, but I wanted to check that I'm not overlooking something.
The text was updated successfully, but these errors were encountered: