标签:vector tor cto span void div tree while link
class Solution { public: void connect(TreeLinkNode *root) { if (root != NULL) { queue<TreeLinkNode*> Q; root->next = NULL; Q.push(root); while (!Q.empty()) { vector<TreeLinkNode*> V; while (!Q.empty()) { TreeLinkNode* t = Q.front(); Q.pop(); if (t->left != NULL) { V.push_back(t->left); } if (t->right != NULL) { V.push_back(t->right); } } V.push_back(NULL); for (int i = V.size() - 1; i > 0; i--) { V[i - 1]->next = V[i]; } for (int i = 0; i < V.size() - 1; i++) { if (V[i] != NULL) { Q.push(V[i]); } } } } } };
标签:vector tor cto span void div tree while link
原文地址:https://www.cnblogs.com/asenyang/p/9746559.html