when I run the code in the command line all the functions work precisely beside the print function. I want print()
to print the nodes when I type p and hit enter, yet it doesn't print until I type a character after that. Can you possibly spot my mistake since I can not figure this out?
print()
Method
void print(struct node *root)
{
if (root != NULL)
{
printf("(");
print(root->left);
printf("%d", root->data);
print(root->right);
printf(")");
}
}
main()
Method
int main(int argc, char** argv)
{
char input;
int n;
char insertt = 'i';
char printt = 'p';
char searchh = 's';
char deletee = 'd';
struct node *root = NULL;
while(scanf("%c%d", &input, &n) !=-1)
{
if(input==insertt)
{
root = insert(root,n);
}
else if(input==deletee)
{
root = deleteNode(root,n);
}
else if(input==searchh)
{
if(search(root,n))
printf("present\n");
else printf("absent\n");
}
else if(input==printt)
{
print(root);
}
}
return 0;
}