Binary Search Tree

来源:互联网 发布:苹果手机截动图软件 编辑:程序博客网 时间:2024/06/06 07:46

Insertion

struct node* newNode(int new_data) {    struct node* temp = (struct node*)malloc(sizeof(struct node));    temp->data = new_data;    temp->left = NULL;    temp->right = NULL;    return temp;}void Insert(struct node** root, int key) {    if ((*root) == NULL) {        *root = newNode(key);    }    if (key < (*root)->data) {        Insert(&(*root)->left, key);    }    if (key > (*root)->data) {        Insert(&(*root)->right, key);    }}
0 0