Implement Insertion of BST

struct node{
    int data;
    struct node *left, *right;
};

struct node* NewNode(int data)
{
    struct node *newnode = (struct node*)malloc(sizeof(struct node));
    newnode->data = data;
    newnode->left = newnode->right = NULL;

    return newnode;
}

struct node* insert(struct node *node, int data)
{
    if(node == NULL) 
        return NewNode(data);

    if(data < node->data)
        node->left = insert(node->left, data);
    else if(data > node->data)
        node->right = insert(node->right, data);

    return node;
}

results matching ""

    No results matching ""