主题:谁能帮我改下顺序二叉树的题
#include<iostream.h>
typedef struct tree //定义二叉树结点
{
int data;
struct tree *lchild,*rchild;
}node;
node create_tree(node*,int&); //建立顺序二叉树
void middle_look(node*); //中序遍历
node delete_treenode(node*,int&); //将二叉树删除某一结点
void main()
{
node *p=NULL;
int array[8]={10,18,3,8,12,2,7,4};
p=create_tree(p,array[]);
middle_look(p);
p=delete_treenode(p,10);
middle_look(p);
}
node create_tree(node root,int& array[])
{
node *point=root;
for (int a=0;point==NULL;a++)
{
if(point==NULL)
{
point=new node;
point->data=array[a];
point->lchild=NULL;
point->rchild=NULL;
}
else
{
node *newnode=new node;
newnode->data=array[a];
switch(array[a]>point->data)
{
case 1:
{
point->rchild=newnode;
point->lchild=NULL;
point=point->rchild;
}
break;
case 0:
{
point->lchild=newnode;
point->rchild=NULL;
point=point->lchild;
}
break;
default:
break;
}
}
}
return root;
}
void middle_look(node& root)
{
cout<<root->data<<' ';
middle_look(root->lchild);
middle_look(root->rchild);
}
node delete_treenode(node& root,int& val)
{
node *p=NULL;
int array[];
void middle_evaluate(node *root)
{
int accumulate=0;
if(root->data!=val)
{
array[accumulate]=root->data;
}
accumulate++;
middle_evaluate(root->lchild);
middle_evaluate(root->rchild);
}
middle_evaluate(*root);
*p=create_tree(p,array[]);
return p;
}
无法编译,应该是参数设置的问题
typedef struct tree //定义二叉树结点
{
int data;
struct tree *lchild,*rchild;
}node;
node create_tree(node*,int&); //建立顺序二叉树
void middle_look(node*); //中序遍历
node delete_treenode(node*,int&); //将二叉树删除某一结点
void main()
{
node *p=NULL;
int array[8]={10,18,3,8,12,2,7,4};
p=create_tree(p,array[]);
middle_look(p);
p=delete_treenode(p,10);
middle_look(p);
}
node create_tree(node root,int& array[])
{
node *point=root;
for (int a=0;point==NULL;a++)
{
if(point==NULL)
{
point=new node;
point->data=array[a];
point->lchild=NULL;
point->rchild=NULL;
}
else
{
node *newnode=new node;
newnode->data=array[a];
switch(array[a]>point->data)
{
case 1:
{
point->rchild=newnode;
point->lchild=NULL;
point=point->rchild;
}
break;
case 0:
{
point->lchild=newnode;
point->rchild=NULL;
point=point->lchild;
}
break;
default:
break;
}
}
}
return root;
}
void middle_look(node& root)
{
cout<<root->data<<' ';
middle_look(root->lchild);
middle_look(root->rchild);
}
node delete_treenode(node& root,int& val)
{
node *p=NULL;
int array[];
void middle_evaluate(node *root)
{
int accumulate=0;
if(root->data!=val)
{
array[accumulate]=root->data;
}
accumulate++;
middle_evaluate(root->lchild);
middle_evaluate(root->rchild);
}
middle_evaluate(*root);
*p=create_tree(p,array[]);
return p;
}
无法编译,应该是参数设置的问题