i wrote a function called insert i want to build a binary tree like this
for that i wrote a function as i read in the tutorialsCode:2 / \ 1 10 / 5
i cant see where is my mistake in that function
Code:#include <stdio.h> typedef struct node{ struct node *left; struct node *right; int data; }node; node insert (node *root,int data); int main(){ node * root; root=insert(root,2); root=insert(root,1); root=insert(root,10); root=insert(root,5); return 0; } node * insert (node *root,int data){ if (!root){ root=malloc(node); root->data=data; return root; }//end if else{ if (data=<root->data){ //start if check return insert(root->left,data); }//end if check else { return insert(root->left,data); } }//end else }//end insert



LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.