搜索树【链式+数组】
3 月,跳不动了?>>> 数组 数组表示二叉树: root left:root*2+1 right:root*2+2 比如 0号节点的左孩子是1 右孩子是2 1号节点的左孩子是3 右孩子是4 2号节点的左孩子是5 右孩子是6 1、定义结构体 int tree[1000]={0}; //存放值的数组 const int NUL=0;//定义0为空 2、找树的最小值和最大值的节点位置 int findMin(int root) //找最小的 往左边找 { if(tree[root*2+1]==NUL) return root; return findMin(root*2+1); } int findMax(int root) //找最小的 往左边找 { if(tree[root*2+2]==NUL) return root; return findMin(root*2+2); } 3、插入节点 void Insert(int root,int v) { if(tree[root]==NUL) { tree[root]=v; return ; } else if(tree[root]>v) { Insert(root*2+1,v); //插入到左树 } else { Insert(root*2+2,v); //插入到右树 } } 4、判断节点是否存在 bool isExist(int