二叉排序树的问题

来源:百度知道 编辑:UC知道 时间:2024/05/06 07:24:23
从键盘读入一组数据以回车('\n')为输入结束标志。
建立二叉排序树并对其进行查找,包括成功和不成功两种情况,并给出查找长度。
实现二叉排序树的插入、删除操作。
谢谢大家!!!

二叉树遍历递归算法:
#include<iostream>
#include<vector>
using namespace std;
struct bitree{
char data;
bitree *lchild;
bitree *rchild;
} ;
void create(bitree *&root){
char ch;
cin>>ch;
if(ch=='#') root=NULL;
else {
root=new bitree;
root->data=ch;
create(root->lchild );
create(root->rchild );
}
}
void preorder(bitree* root)
{ if(root==NULL) return;
else{
cout<<root->data;
preorder(root->lchild);
preorder(root->rchild); }
}
int main(int argc, char* argv[])
{ bitree *root;
create(root);
preorder(root);
}

二叉树遍历非递归算法:
#include<iostream>
#include<vector>
using namespace std;
struct bitree{
char data;
bitree *lchild;