C++层次遍历输入二叉树(用STL)
在设置队列的时候,注意类型是queue<Node *> Tqueue,如果不写星号,push时会创建一个新的节点入队,这样整棵树就不是连通的;而加了星号,是把指针地址入队,所以在操作的时候是在原节点上操作,这样经过左孩子和右孩子赋值,才可以把整棵树连通。输出print函数是一个简单的中序遍历。
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
struct Node{
Node *left;
Node *right;
int c;
}Tree[110];
int loc;
Node* creat(int a){
Tree[loc].left = Tree[loc