#include <stdio.h>
#include <stdlib.h>
struct Node{
char data;
struct Node * left;
struct Node * right;
};
void Create(Node ** root){
char ch;
scanf("%c", &ch);
if(ch == '#') return;
*root = (Node *)malloc(sizeof(struct Node));
(*root) -> data = ch;
(*root) -> left = NULL;
(*root) -> right = NULL;
Create( &( (*root) ->left ) );
Create( &( (*root) ->right) );
}
void Pre(Node * root){
if(root == NULL) return;
printf("%c ", root -> data);
Pre(root -> left);
Pre(root -> right);
}
int main(){
Node * head;
Create(&head);
printf("input oVer\nPre order: ");
Pre(head);
printf("\n");
}
Binary Tree_build & travserse(二叉树建立,遍历)
最新推荐文章于 2025-08-16 17:39:51 发布
本文介绍了一种使用C语言实现二叉树的方法,包括二叉树的创建过程及前序遍历算法。通过递归的方式实现了节点的创建与连接,并通过前序遍历来展示树形结构的内容。

360

被折叠的 条评论
为什么被折叠?



