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

来源:互联网 发布:cc域名注册哪里便宜 编辑:程序博客网 时间:2024/06/15 04:20
#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");}
0 0
原创粉丝点击