大学计算机专业课程中数据结构各章的算法设计
源代码在线查看: 8-10.cpp
#include "Tree1.h"
TreeNode1* insert(char ch,TreeNode1 *p)
{
if(p==NULL)
p=new TreeNode1(ch);
else
{
if(chdata)
p->left=insert(ch,p->left);
else
p->right=insert(ch,p->right);
}
return p;
}
void create(Tree1 &t1,char str[])
{
t1.root=NULL;
int i=0;
cout while(str[i]!='\0')
{
cout t1.root=insert(str[i],t1.root);
i++;
}
cout }
TreeNode1* search(Tree1 &t1,char ch)
{
TreeNode1 *p=t1.root,*find=NULL;
cout while(p!=NULL&&find==NULL)
{
cout if(ch==p->data)
find=p;
else
if(chdata)
p=p->left;
else
p=p->right;
}
return find;
}
void main()
{
char *str="3258793146";
Tree1 t1;
create(t1,str);
t1.inorder();
TreeNode1 *find=search(t1,'1');
if(find!=NULL)
cout else
cout char ch='0';
find=search(t1,ch);
if(find!=NULL)
cout else
cout }