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

📄 creatree.c

📁 《数据结构》教材源程序,可以让你轻松的根据教材学习数据结构
💻 C
字号:
#include <stdio.h>
#define m 3
typedef char datatype;
typedef struct node {
     datatype data;
     struct node *child[m];
} node,*tree;
void createtree(tree *p)
 {/*按前序遍历顺序建立一棵3度树的递归算法*/
   
   int i; char ch;
   
   if ((ch=getchar())==' ')  *p=NULL;
   else
      {
	 *p=(tree) malloc (sizeof(node));
	 (*p)->data=ch;
	 for (i=0;i<m;++i)
	   createtree(&(*p)->child[i]);
      }
     
   }
void postorder(tree p)
 {/*树的后序遍历*/
    int i;
    if (p!=NULL)
     {
      
      for (i=0;i<m;++i)
	 postorder(p->child[i]);
      printf("%c",p->data);
      }
  }
 main()
 {
   tree t;
   printf("please input the preorder sequence of the tree:\n");
   createtree(&t);
   printf("\nthe postorderis:");
   postorder(t);
}

⌨️ 快捷键说明

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