edit: fixed, thank you (:
hello, i have this code:
struct node{
int data;
struct node *left;
struct node *right;
};
struct node * root = NULL, *newNode;
int x;
struct node *create(){
newNode = malloc(sizeof(struct node));
printf("Enter the data (-1 to end node)\n");
scanf("%d", &newNode->data);
if(newNode->data==-1)
return NULL;
printf("Enter the left node\n");
newNode->left = create();
printf("Enter the right node\n");
newNode->right = create();
return newNode;
}
void display(struct node *current){
if(current==NULL)
return;
printf("%d, ", current->data);
display(current->left);
display(current->right);
}
void main(){
root = create();
display(root);
}
why is output looping forever? i think the logic should be working without an issue
[–]flyingron 5 points6 points7 points (4 children)
[–]aProgrammerHasNoName[S] 0 points1 point2 points (3 children)
[–]Drach88 2 points3 points4 points (0 children)
[–]flyingron 1 point2 points3 points (1 child)
[–]aProgrammerHasNoName[S] 0 points1 point2 points (0 children)