Loading... ``` #include<bits/stdc++.h> #pragma GCC optimize(2) using namespace std; struct tree{ int left; int right; }; tree t[1000]; int dfs(int n){ // 深度 if(!n) return 0; return max(dfs(t[n].left), dfs(t[n].right)) + 1; } void f(int n){ // 先序 cout << n << " "; if(t[n].left) f(t[n].left); if(t[n].right) f(t[n].right); } void s(int n){ // 中序 if(t[n].left) s(t[n].left); cout << n << " "; if(t[n].right) s(t[n].right); } void e(int n){ // 后序 if(t[n].left) e(t[n].left); if(t[n].right) e(t[n].right); cout << n << " "; } int main(void){ int n; cin >> n; for(int i = 1; i <= n; i++) cin >> t[i].left >> t[i].right; return 0; } ``` Last modification:October 28, 2021 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed