Hi All
I am trying to create Binary tree from array elements but when I tried to run this program, it was giving segementation fault error.
The code is as follow:
Could any body help me where is the problem.Code:#include<stdio.h> #include<stdlib.h> struct node { struct node *left; struct node *right; int data; }; void insert(struct node **p,int num) { if ( *p == NULL ) { (*p) = (node *)malloc(sizeof(struct node)); (*p)->left = NULL; (*p)->right = NULL; (*p)->data = num; } else { if( num == (*p)->data) return; } if ( num < (*p)->data) insert(&((*p)->left),num); else insert(&((*p)->right),num); } void createBinary(struct node *ptr,int a[],int i) { int m; for ( m = 0;m< i; m++ ) { insert( &ptr,a[m]); } } int main() { int a[] = {11,12,13,14,15}; int size1 =0; struct node *ptr = NULL; size1=sizeof(a) / 4; createBinary(ptr,a,size1); }
Thanks



LinkBack URL
About LinkBacks


