


#include <stddef.h>   // NULL
#include <stdlib.h>
#include <stdio.h>
#define MaxSize 10
typedef struct node {
    int data;
    struct node* lchild, * rchild;
} TreeNode;
TreeNode *create(int nums[], int n);
void preorder(TreeNode *root);


TreeNode* newNode(int v) {
    TreeNode* node = (TreeNode*)malloc(sizeof(TreeNode));
    node->data = v;
    node->lchild = node->rchild = NULL;
    return node;
}
void insert(TreeNode** root, int x)
{
    if (*root == NULL) {
        *root = newNode(x);
        return;
    }
    if ((*root)->data < x) {
        insert(&(*root)->lchild, x);
    }
    else {
        insert(&(*root)->rchild, x);
    }
}
TreeNode *create(int nums[], int n)
{
    TreeNode* root = NULL;
    for (int i = 0; i < n; i++) {
        insert(&root, nums[i]);
    }
    return root;
}
void preorder(TreeNode* root)
{
    if (root == NULL) {
        return;
    }
    printf("%d ", root->data);
    preorder(root->lchild);
    preorder(root->rchild);
}

int main(int argc, char* argv[])
{
    int nums[MaxSize] = { 7, 4, 3, 8, 10, 12, 17, 0, -1, 3 };

    TreeNode* root = create(nums, MaxSize);
    preorder(root);
    return 0;
}

