특정 운동 실습을보십시오.
주제
이진 트리의 예비 순서의 순서에 따라 : 7, -7,8,#, -3,6,#,#, 9, 9,#, -5,#,#, Order and Post -Order 트래버스
암호
java.util.scanner {public static static int count; rchild; propubly public public a public x) {this.data = x;} / ** * 예비 시퀀스 열 * * @return * / public treenode createbtree ()에 따라 이진 트리를 구성하기 위해 이진 트리를 구성합니다. 널; createbtree (); = createbtree ();} return root;} * 라이브 순차적으로 * * @param void pretraverse (treenode root) {if (root! = null) {sysem.out.print root.d ata + ""); root = intraverse (root.lchild). 정적 D Postraverse (적절한 루트) {if! = null (root.lchild) (root.rchild); ) {system.in) (cin.hasnext (); ceatebtree ()는 pretraverse를 통과했다. }}}
이진 트리의 깊이
다음은 이진 트리의 재귀 알고리즘을 실현하는 것입니다. 아이디어는 비어 있으면 깊이가 0입니다. 그렇지 않으면 깊이는 왼쪽 하위 트리의 깊이와 오른쪽 트리의 최대 값과 같습니다.
클래스 노드 {왼쪽 노드; binarytree () {root = null;} // 편의를 위해 초기화 된 바이너리 트리를 직접 쓸 것입니다. ) NODE NODE ( "B"); node2; node3; node4; = return 0; 정적 void main (string [] art) {binarytree tree = new binarytree ();