首页 > 代码库 > 二叉树的层次遍历法

二叉树的层次遍历法

 

 

void print_by_level_2(treeNode* Root) {   if(! Root)     return;    deque<treeNode*> dequeTreeRoot;      dequeTreeRoot.push_back(Root);      while(!dequeTreeRoot.empty()) {              treeNode *temp = dequeTreeRoot.front();              dequeTreeRoot.pop_front();              cout << temp->data << " ";              if (temp->lchild)                  dequeTreeNode.push_back(temp->lchild);              if (temp->rchild)                  dequeTreeNode.push_back(temp->rchild);      }//end while  }  

 

二叉树的层次遍历法