#include
#include
#include
typedef char elemtype;
struct bnode
{
elemtype data;
int top;
struct bnode *lchild,*rchild;
struct bnode *llink,*rlink;
};
const N=10;
void push(struct bnode *p)
{
struct bnode *q;
new(q);
q=p;
if(top!=0)
{
}
struct bnode *set_tree()
{
struct bnode *t,*p,*q;
int i;
char d;
t=new(bnode);
t->data=rand() % 26 + 'A';
t->lchild=NULL; t->rchild=NULL;
for (i=1;ip->data) {q=p; p=p->rchild;}
else { q=p; p=p->lchild;}
p=new(bnode);
p->data=d; p->lchild=NULL; p->rchild=NULL;
if (d>q->data)
q->rchild=p;
else q->lchild=p;
}
return t;
}
void pre_order(struct bnode *t)
{
if (t!=NULL)
{
coutdatalchild);
pre_order(t->rchild);
}
}
void mid_order(struct bnode *t)
{
if (t!=NULL)
{
mid_order(t->lchild);
coutdatarchild);
}
}
void write(struct bnode *h)
{
struct bnode *p;
p=h;
while(p->rlink!=h)
{
coutdata;
p=p->rchild;
}
coutdata;
}
struct bnode *Conver(struct bnode *t)
{
struct bnode *p,*q,top;
q=p=t;
top=0;
while(p!=NULL||top!=0)
{
if(p!=NULL)
{
q->rlink=p;
p->llink=q;
q=q->rlink;
push(p);
p=p->lchild;
}
else
{
pop(p);
p=p->rchild;
}
}
q->llink->rlink=t;
t->llink=q->llink;
return t;
}
void main()
{
struct bnode *t;
//srand((unsigned)time(NULL));
t=set_tree();
cout<<endl<<"preorder"<<endl;
pre_order(t);
cout<<endl<<"midorder"<<endl;
mid_order(t);
cout<<endl;
}
首先栈的定义不会,此外帮我看下COVER过程,能实现嘛?编不下去了啊,这块不是很懂,忘谁能给个正确的程序 谢谢 不盛感激
给个过程吧 队的定义真不会 麻烦了
|