0

CAN YOU FIND THE ERRORS IN THIS PROGRAM??

#include<stdio.h> #include<stdlib.h> struct tree { int data; struct tree*leftchild; struct tree*rightchild; }*root=NULL; void insert(int data) { struct tree*tempnode=(struct tree*)malloc(sizeof(struct tree)); struct tree*current; struct tree*parent; tempnode->data=data; tempnode->leftchild=NULL; tempnode->rightchild=NULL; if(root=NULL) { root=tempnode; } else { current=root; parent=NULL; while(1) { parent=current; if(data<parent->data) { current=current->leftchild; if(current=NULL) { parent->leftchild=tempnode; return; } } else { current=current->rightchild; if(current=NULL) { parent->rightchild=tempnode; return; } } } } } int main() { int i; int arr[8]={22,33,12,42,23,43,25,35}; for(i=0;i<8;i++) { insert(arr[i]); printf("success"); } return 0; }

20th Jun 2019, 6:31 AM
LOGESH P
LOGESH P - avatar
2 Réponses
+ 3
Line 18: `if ( root = NULL )` should be `if ( root == NULL )` Line 32 and 41: `if ( current = NULL )` should be `if ( current == NULL )`
20th Jun 2019, 7:11 AM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
0
Tq so much bro
22nd Jun 2019, 4:41 AM
LOGESH P
LOGESH P - avatar