您的位置:首页 > 产品设计 > UI/UE

Binary Tree_build & travserse(二叉树建立,遍历)

2016-10-31 22:12 239 查看
#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");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: