6.3w+
社区成员
#include<iostream>
#include <string>
#include<stdio.h>
using namespace std;
struct tree {
char info;
struct tree *left,*right;
};
class biTree
{
public:
biTree(char *s, int n );
~biTree();
struct tree *create_btree(struct tree *root,struct tree *r,char info);
void InOrder(struct tree *T); //中序递归遍历二叉树
private:
struct tree *root;
};
//******************************************
// the main function
//******************************************
int main()
{
return 0;
}
biTree::biTree(char *a, int n )
{
root = '\0';
char *s;
s = a;
do {
s = a;
n--;
if (!root){
root=biTree::create_btree(root,root,*s);
}
else{
//create_btree(root,root,*s);
}
a++;
} while ( n ) ;
}
struct tree biTree::*create_btree(struct tree *root,struct tree *r,char info)
{
if (r ==0 )
{
r=new (struct tree);
if ( r == 0)
{
printf("Out of memory\n");
return 0 ;
}
r->left= 0;
r->right=0;
r->info=info;
if (root)
{
if(info<root->info) root -> left=r;
else root->right=r;
}
else
{
r->right=0;
r->left = 0;
}
}
if (info < r->info)
create_btree(r,r->left,info);
if(info>=r->info)
create_btree(r,r->right,info);
}
struct tree* biTree::create_btree(struct tree *root,struct tree *r,char info)
//*号写错地方了