L2-035 完全二叉树的层序遍历
#include <bits/stdc++.h>
using namespace std;
const int N = 50;
int tr[N];
int n;
void dfs(int cnt) {
if (cnt > n) return;
dfs(cnt * 2);
dfs(cnt * 2 + 1);
cin >> tr[cnt];
}
int main() {
cin >> n;
dfs(1);
for (int i = 1; i <= n; i++) {
cout << tr[i] << " "[i == n];
}
return 0;
}