node* rl(){return left;}
node* rr(){return right;}
void dele(node *&ptr)//删除值为item所在结点 {
if(ptr->rl()==NULL&&ptr->rr()==NULL)

ptr=NULL;
else if(ptr->rr()==NULL)
ptr=ptr->rl();
else
ptr=ptr->rr();
}
private:
int data;
node *left;//左孩子结点
node *right;//右孩子结点
};
int main()
{
int t,i=0,j;
cout<<"输入数字个数(结点个数):";
cin>>t;
cout<<"输入"<<t<<"个数字,数字之间用空格隔开:"; cin>>j;
node *x=new node(j);
for(;i<t-1;i++)
{
cin>>j;
x->insert(x,j);
}
cout<<"中序遍历为:";
x->inorder(x);//作中序遍历
cout<<"\n输入操作(当输入-1时程序结束):"<<endl; cin>>j;
while(j!=-1)
{
node *t=x->find(x,j);//定位结点 if(t!=NULL)
{
node *&y=x->findy(x,j);
x->dele(y);
-25-
cout<<"中序遍历为:";
x->inorder(x);
}
else cout<<"无"<<j;
cout<<"\n输入操作(当输入-1时程序结束):"<<endl; cin>>j;
}
return 0;
}
-26-
顺序存储结构c
#include"stdio.h"
#include"malloc.h"
#include"windows.h"
#define endflag 999999
#define N 1000
int b[N];
typedef struct
{
int data;
int other;
int flag1;
}Link;
void Build(Link a[N])
{
int w,i,j,k;
for(i=0;i<=N;i++)
{
a[i].flag1=0;
a[i].data=0;
}
printf("\n\t\t\t 请输入树的根结点:"); scanf("%d",&a[1].data);
a[1].flag1=1;
printf("\n\t\t\t 请输入结点个数:"); scanf("%d",&k);
for(j=1;j<=k;j++)
{
printf("\n\t\t\t 请输入结点的数值:"); scanf("%d",&w);
printf("\n\t\t\t 第%d位:%d",j,w); a[0].data=w;
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-26533-9.html
我今天要刷屏
一是当时我们实力不够
DF26