#include <string> #include <iostream> #include <queue> using namespace std;
using node = struct Node; using tree = node * ; struct Node { int data; tree left; tree right; }; int N,L; //n个数,l组测试数据
//在树T中插入a tree insert(tree T, int a) { if (T==NULL) { tree tmp = new node; tmp->data = a; tmp->left = NULL; tmp->right = NULL; T = tmp; return T; } if (T->data > a) { T->left = insert(T->left, a); } else if (T->data < a) { T->right = insert(T->right, a); }
return T; }
//建立一棵N个节点的树 tree create( ) { tree T = NULL; for (int i = 0; i < N; i++) { int tmp; cin >> tmp; T = insert(T, tmp); } return T; }
queue<tree> que; que.push(T); while (!que.empty()) { tree T =que.front(); que.pop(); str +=to_string(T->data); if ((T->left)) que.push(T->left); if ((T->right)) que.push(T->right); } }