分享

编程论坛-平衡二叉树[原创]

 accesine 2005-09-23

编程论坛『 C++教室 』→平衡二叉树[原创]

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


……………………(未完,阅读全文请点顶部链接)

玩偶

楼主的头文件是自己写的吧??

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多