You are viewing a single comment's thread. Return to all comments →
void topView(Node* root) { std::queue<std::pair<int, Node*>> q; q.push(std::make_pair(0,root)); while (!q.empty()) { auto i = q.front(); if(i.second != nullptr) { q.push(std::make_pair(i.first-1, i.second -> left)); q.push(std::make_pair(i.first+1, i.second -> right)); std::cout<<i.second->data<<' '; } q.pop(); i=q.front(); } }
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 →