Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void addBrother(node&* begin, node&* last, node* brother) {
- if (brother) {
- if (begin) {
- last->brother = brother;
- last = brother;
- } else {
- begin = last = brother;
- }
- }
- }
- void bfs(node* node) {
- while(node) {
- node* brothersBegin = nullptr;
- node* brothersLast = nullptr;
- for (node* item = node; item; item = item->brother) {
- addBrother(brothersBegin, brothersLast, item->left);
- addBrother(brothersBegin, brothersLast, item->right);
- }
- node = brothersBegin;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement