二叉树的java实现: 1packagecom.peter.java.dsa.common;23importjava.util.ArrayList;45publicclassBinaryTree {6privateTreeNode root;7privateintsize = 0;89publicBinaryTree() {10//TODO Auto-generated constructor stub11}1213publicBinaryTree(intvalue) {14//TODO Auto-generated constructor stub15this.root ...
}voidmain(){ //前序创建树,中序输出树 BiTree T;//根节点 CreateBiTree(&T); ForEachTree(T); } java版本实现: 由于java没有c的指针,所以相对于c来说实现起来比较别扭,但思路没问题 在java中,不管这个节点是不是空节点,都会申请空间,只不过这个节点的数据、左子树、右子树都是null,但这个节点不是null...
typedef int status; typedef struct BiNode { char data; struct BiNode *lchild,*rchild; }BiTNode,*BiTree; //定义二叉树 status createBiNode(BiTree &t) { char ch; ch=getchar(); if(ch==' ') t=NULL; else { //先输入根节点 在左子树 再右子树 if(!(t=(BiTNode *)malloc(sizeof(BiTNo...
Integer[] a = {3,9,20,null,null,15,7,null,null,null,null};inti=1;BinNoderoot=newBinNode(a[0]);// 根节点BinNodecurrent=null;Integervalue=null;//层序创建二叉树LinkedList<BinNode> queue =newLinkedList<BinNode>(); queue.offer(root);while(i...