新建 文本文档.txt

来自「这是个数据结构的算法(二叉树的实现)」· 文本 代码 · 共 41 行

TXT
41
字号
#include"stdio.h"
#include"stddef.h"

typedef struct tree{
     char data;
     struct tree *rchild,lchild;
     }
 
stuct tree *createtree(struct tree *root,struct tree *r,char info)
 {
    if(!r)
      {
        r=(struct tree *)malloc(sizeof(struct tree));
        if(!r)
         { printf("mem over");
            exit(0);
         }
       r->rchild=NULL;
       r->lchild=NULL;
       r->data=info;
       if(!root)
          return r;
       if(info<root->data)
          return root->lchild=r;
        else
         retrun root->rchild=r;
          retrun r;
     }
   if (info<r->data)
     createtree(r,r->lchild,info);
   else
    createtree(r,r->rchild,info);
  retrun root;
}

void print_tree(struct tree *r)
{
  if(r)
   {
     printf("%c",r->data);
     print_tree(r->rchild);

⌨️ 快捷键说明

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