Home > other >  Binary sort tree and insert
Binary sort tree and insert

Time:10-21

Hello, I write my own binary sort tree algorithm, feel not wrong, but a run up, will automatically stop, seek help from a great god,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#include
#include
Typedef struct node {
int data;
Lchild struct node * and * rchild;
} BSTNode;
Typedef BSTNode * BinTree;
//binary sort tree insert, the new input data is inserted into the leaf node
BinTree BinSort (BinTree bt, BSTNode * p) {
BSTNode * h * f;
H=bt;
While (h) {
F=h;
If (h - & gt; Data> P - & gt; Data) h=h - & gt; Lchild;
If (h - & gt; Data

}
If (bt==NULL) bt=p;
Else if (f - & gt; Data> P - & gt; Data) f - & gt; Lchild=p;
The else f - & gt; Rchild=p;
Printf (" \ nI am executed \ n ");
The return of bt;
}
BinTree CreateBinTree () {//input data
BinTree bt=NULL;
Int k;
BSTNode * p;
Printf (" both Please input a number 0 to end: \ n ");
The scanf (" % d ", & amp; k);
While (k) {
P=(BSTNode *) malloc (sizeof (BSTNode));
P - & gt; data=https://bbs.csdn.net/topics/k;
P - & gt; Lchild=p - & gt; Rchild=NULL;
Bt=BinSort (bt, p);
The scanf (" % d ", & amp; k);
}
The return of bt;
}


Int main () {
BinTree bt;
Bt=CreateBinTree ();
}

  • Related