You are viewing a single comment's thread. Return to all comments →
This was a fun problem where I got to make use of the linked lists we learned in the last chapter (:
#include <list> void LevelOrder(node * root) { list<node*> nodes; if (root) { nodes.push_back(root); } for (list<node*>::iterator it = nodes.begin(); it != nodes.end(); it++) { printf("%d ", (*it)->data); if ((*it)->left) { nodes.push_back((*it)->left); } if ((*it)->right) { nodes.push_back((*it)->right); } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Level Order Traversal
You are viewing a single comment's thread. Return to all comments →
This was a fun problem where I got to make use of the linked lists we learned in the last chapter (: