二叉树的层次遍历

来源:互联网 发布:刷单源码 编辑:程序博客网 时间:2024/05/29 04:47

参考视频:https://www.youtube.com/watch?v=86g8jAQug04



struct Node{  char data;  Node* left;  Node* right;}void levelOrder(Node* root){  if(root==null) return ;  queue<Node *> Q;  Q.push(root);  while(!Q.empty()){     Node* current=Q.front();     if(current->left!=null)         Q.push(current->left);     if(current->right!=null)       Q.push(current->right);     Q.pop();  }}


0 0
原创粉丝点击