大家好,我自己寫的二叉排序樹演算法,自己感覺沒有錯,但一運行起來,就自動停止。求大神幫助下。
-----------------
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node *lchild,*rchild;
}BSTNode;
typedef BSTNode * BinTree;
//二叉排序樹的插入,把新輸入的資料插入到葉子結點
BinTree BinSort(BinTree bt,BSTNode *p){
BSTNode *h,*f;
h=bt;
while(h){
f=h;
if(h->data>p->data) h=h->lchild;
if(h->data<p->data) h=h->rchild;
}
if(bt==NULL) bt=p;
else if(f->data>p->data) f->lchild=p;
else f->rchild=p;
printf("\nI am executed\n");
return bt;
}
BinTree CreateBinTree(){ //輸入資料
BinTree bt=NULL;
int k;
BSTNode *p;
printf("Please input a number 0 to end:\n");
scanf("%d",&k);
while(k){
p=(BSTNode *)malloc(sizeof(BSTNode));
p->data=https://bbs.csdn.net/topics/k;
p->lchild=p->rchild=NULL;
bt=BinSort(bt,p);
scanf("%d",&k);
}
return bt;
}
int main(){
BinTree bt;
bt=CreateBinTree();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/181247.html
標籤:數據結構與算法
上一篇:qml 與C++互動問題
下一篇:一個特別好用的服務器
