這個(gè)東東就是要花一點(diǎn)時(shí)間畫圖研究。
以下是我的代碼。
寫得差請(qǐng)見諒
#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
……………………(未完,閱讀全文請(qǐng)點(diǎn)頂部鏈接)
樓主的頭文件是自己寫的吧??
聯(lián)系客服