kings169524
这个东东就是要花一点时间画图研究。 以下是我的代码。 写得差请见谅 #include <status.h>
typedef struct BT{ int data; struct BT* l; struct BT* r; int bl; BT(int d); }BT;
BT::BT(int d){ l=r=NULL; data=d; bl=0; }
void clear(BT* p){ if(p){ clear(p->l); clear(p->r); delete(p); } }
void print(BT* p){ cout<<"data="<<p->data<<‘\t‘<<"bl="<<p->bl<<endl; }
void f_p(BT* T){ if(T!=NULL){ print(T); f_p(T->l); f_p(T->r); } }
void m_p(BT* T){ if(T!=NULL){ m_p(T->l); print(T); m_p(T->r); } }
void Trans(BT* T){ cout<<"\nfront trans:\n"; f_p(T); cout<<endl; cout<<"\nmid trans:\n"; m_p(T); cout<<endl; }
void Rotate_1(BT* &p){ BT* T=p->l; p->bl=0; T->bl=0; p->l=T->r; T->r=p; p=T; }
void Rotate_2(BT* &p){ BT* T=p->l->r; if(T->bl==0){ p->l->b
……………………(未完,阅读全文请点顶部链接)
|