对于我的 C 代码构建一个二叉搜索树并在其一侧打印树不打印任何东西?

For my C code to construct a binary search tree and print the tree on its side is not printing anything?

我正在尝试编写一个程序来构建一个二叉搜索树并在其一侧打印树。以整数序列的形式读取用户的输入,并根据深度缩进输出树,每行一个值。但是,我的代码正在运行但没有在控制台上打印任何内容? 我认为我的插入功能可能有问题,但我不确定。

#include <stdio.h>
#include <stdlib.h> 
struct node {
  int data;
  struct node *left, *right;
};  
typedef struct node node;   
node *insert(node *t, int a){ //insert values in tree
  node* tmp= (node*)malloc(sizeof(node));;  
  if (t==NULL) {
      tmp->data = a;
      tmp->left = NULL;
      tmp->right = NULL;
      return(tmp);
    }
  else if (a < t->data)
      t->left = insert(t->left,a);
    else
      t->right = insert(t->right,a);    
  return(t);
}
void print( node *t, int depth) {
    int i;
    if (t == NULL) 
        return;         
    print(t->right, depth + 1); 
    for (i = 0; i < 4 * depth; ++i)
        printf(" ");            
    printf("%d\n", t->data);        
    print(t->left, depth + 1);
}   
int main() {
    node *root= NULL;
    int n,a,i;
    printf("Enter number of values "); //7
    scanf("%d", &n);    
    printf("\nEnter numbers "); //10 6 14 4 8 12 16
    for (i = 0; i < n; ++i) {
        scanf("%d", &a);
        insert(&root, a);
    }   
    print(root, 0); 
    return 0;
}
Input: 10 6 14 4 8 12 16
Expected output:
        16
    14
        12
10
        8
    6
        4

insert的签名是

node *insert(node *t, int a) // t is a pointer to node

但是你传递的是指向节点的指针

insert(&root, a);

我想你想要

root = insert(root, a);