文章
25
粉丝
0
获赞
140
访问
4.3k
单独处理第一个根节点的父亲为-1,其余正常在建树过程输出
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int data;
struct node *lchild,*rchild;
}*BitTree;
//创建二叉排序树并且输出父亲
void BST(BitTree &T,int x){
if(T == NULL){
T = new node;
T ->data = x;
T ->lchild = NULL;
T ->rchild = NULL;
return;
}
if(T->data == x)
return;
else if(x < T->data){
if(T->lchild == NULL)
cout<<T->data<<endl;
BST(T->lchild,x);
}
else{
...
登录后发布评论
暂无评论,来抢沙发