题解 | #二叉树遍历#
二叉树遍历
https://www.nowcoder.com/practice/4b91205483694f449f94c179883c1fef
#include <bits/stdc++.h> using namespace std; typedef struct node{ char data; struct node *lchild,*rchild; }*BitTree; void CreateTree(BitTree &T){ char c; cin >> c; if(c == '#') T = NULL; else{ T = new node; T -> data = c; CreateTree(T -> lchild); CreateTree(T -> rchild); } } void InOrderPrint(BitTree T){ if(T != NULL){ InOrderPrint(T -> lchild); cout << T -> data << " "; InOrderPrint(T -> rchild); } } int main(){ BitTree T; CreateTree(T); InOrderPrint(T); }
模板题
#算法#