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

📄 oldertree.c

📁 c语言一些基础编码
💻 C
字号:
/* 标准文档模板SHY3_3从大到小的顺序输出二叉排序树的各结点 */

#include "Stdio.h"
#include "Conio.h"

#include <stdio.h>
#include <conio.h>

#include <stdlib.h>
#include <malloc.h>


#define M 100
#define Null 0

typedef struct node /* 二叉链表类型的定义*/
{
 int data;
 struct node *lchild,*rchild;
} BITREE;

BITREE *InsertBst(BITREE *t,BITREE *s); /* 插入结点到二叉树中 */
void DestOrder(BITREE *t);             /*从右子树开始遍历二叉排序树*/
BITREE *creatord();                    /* 建立二叉排序树 */


void DestOrder(BITREE *tr) /*从右子树开始遍历二叉排序树*/
{
 if(tr!=Null)
 {
  DestOrder(tr->rchild);
  printf("%4d",tr->data);
  DestOrder(tr->lchild);
 }
}

BITREE *creatord() /* 建立二叉排序树 */
{
 BITREE *tr,*s;
 int x;
 tr=Null;
 printf("\nInput the node value of the tree root:\n");
 scanf("%d",&x);
 while(x!=0)
 {
  s=(BITREE *)malloc(sizeof(BITREE));
  s->data=x;
  s->lchild=Null;
  s->rchild=Null;
  tr=InsertBst(tr,s);
  printf("\nInput another node's value:");
  scanf("%d",&x);
 }
 return (tr);
}
/* creatord */

BITREE *InsertBst(BITREE *tr,BITREE *s)
/* 将新结点s插入到由tr所指的二叉排序树中 */
{
 BITREE *f,*p;
 p=tr;
 while(p!=Null)
  {
   f=p;
   if(s->data==p->data) return tr;
   if(s->data<p->data) p=p->lchild;
   else
     p=p->rchild;
  }
 if(tr==Null) return (s);
 if(s->data<f->data) f->lchild=s;
 else f->rchild=s;
 return (tr);
 }
/* InsertBst */



 int main()
 {
  BITREE *root;
  printf("\n");
  root=creatord();
  DestOrder(root);
  printf("\n");
  return (1);
 } /* main */

⌨️ 快捷键说明

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