⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pingheng.c

📁 一个vc++环境下的数据结构的课程设计报告源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
 lc->rchild=T;T=lc;
 return T;
}

struct BST *l_rotate(struct BST *T)                         /*左旋转函数*/
{
 struct BST *rc;
 rc=T->rchild;
 T->rchild=rc->lchild;
 rc->lchild=T;T=rc;
 return T;
}
/*******************************中序遍历二叉排序树*************************/
void InOrderTraverse(struct BST **T)
{
 if(*T)
 {
  InOrderTraverse(&(**T).lchild);
  printf("%d\n",(**T).data);
  InOrderTraverse(&(**T).rchild);
 }
 else return;
}
/*******************************前序遍历二叉排序树*************************/
void PreOrderTraverse(struct BST **T)
{
 if(*T)
 {
  printf("%d\n",(**T).data);
  PreOrderTraverse(&(**T).lchild);
  PreOrderTraverse(&(**T).rchild);
 }
 else return;
}







/*********************************************************************/
/****************************有关显示平衡二叉树的函数*****************/
/*********************************************************************/







/*************************将二叉树显示在右边的界面中******************/
void show(int *a,int *b)
{
 window(60,1,61,1);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(60,1,61,1);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(50,3,51,3);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(50,3,51,3);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(70,3,71,3);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(70,3,71,3);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(45,5,46,5);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(45,5,46,5);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(55,5,56,5);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(55,5,56,5);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(65,5,66,5);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(65,5,66,5);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(75,5,76,5);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(75,5,76,5);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(42,7,43,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(42,7,43,7);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(48,7,49,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(48,7,49,7);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(52,7,53,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(52,7,53,7);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(58,7,59,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(58,7,59,7);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(62,7,63,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(62,7,63,7);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(68,7,69,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(68,7,69,7);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(72,7,73,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(72,7,73,7);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(78,7,79,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=*b)
 {
  window(78,7,79,7);
  textbackground(RED);
  clrscr();
 }
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
}
 /*****************************去掉改变的红方框************************/
void show1(int *a,int *b)
{
 window(60,1,61,1);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(50,3,51,3);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(70,3,71,3);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(45,5,46,5);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(55,5,56,5);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(65,5,66,5);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(75,5,76,5);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(42,7,43,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(48,7,49,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(52,7,53,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(58,7,59,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(62,7,63,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(68,7,69,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(72,7,73,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
 window(78,7,79,7);
 textbackground(CYAN);
 clrscr();
 if(*a!=0) printf("%d",*a);
 a++;
 b++;
}



/*****************************求平衡二叉树的高度*********************/
void height(struct BST **T)   /*高度的值存在e内*/
{
 if(*T)
 {
  d++;
  if(d>e) e=d;
  height(&(**T).lchild);
  height(&(**T).rchild);
  d--;
 }
 else return;
}
/*****************************层次遍历并顺序存储二叉树********************/
void save(struct BST **T,int *order)    /*order为存储数组的指针*/
{
 struct DLZZ Q;                          /*层次遍历而叉树*/
 struct BST *p;
 e=pow(2,e-1);
 InitQueue(&Q);
 EnQueue(&Q,*T);
 while(Q.front!=Q.rear)
 {
  DeQueue(&Q,&p);
  e--;
  *order=p->data;
  order++;
  if(e>=0)
  {
   if(p->lchild!=NULL) EnQueue(&Q,p->lchild);
   else EnQueue(&Q,&zero);
   if(p->rchild!=NULL) EnQueue(&Q,p->rchild);
   else EnQueue(&Q,&zero);
  }
 }
}

/************************层次遍历用到的队列函数***********************/
void InitQueue(struct DLZZ *Q)
{
 (*Q).front=(*Q).rear=(struct DL *)malloc(sizeof(struct DL));
 if(!(*Q).front) exit (-1);
 (*Q).front->next=NULL;
}


void EnQueue(struct DLZZ *Q,struct BST *e)
{
 struct DL *p;
 p=(struct DL *)malloc(sizeof(struct DL));
 if(!p) exit (-1);
 p->data=e;
 p->next=NULL;
 (*Q).rear->next=p;
 (*Q).rear=p;
}


void DeQueue(struct DLZZ *Q,struct BST **e)
{
 struct DL *p;
 if((*Q).front==(*Q).rear) return;
 p=(*Q).front->next;
 *e=p->data;
 (*Q).front->next=p->next;
 if((*Q).rear==p) (*Q).rear=(*Q).front;
 free(p);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -