how to find out the inorder successor of a node in a tree??
Answers were Sorted based on User's Feedback
Answer / atul kabra
Suppose we want to fint the inorder successor of N. Then
traverse one time right from N. And then traverse a left
subtree until u will get left pointer null node.
s=n->right;
while(s->left!=NULL)
s=s->left;
printf("\nInoder Successor is %d",s->info);
| Is This Answer Correct ? | 27 Yes | 42 No |
inorder trraversal is
left - vertex - right.
hence to find the successor of a node.
consider N node . we have to find the inorder successor of
N.
then,
if(n -> right != NULL)
n = n -> right. /* this is the successor of n.
else
{
n = pop();
(/* we have to pop the address of the node above n, which
we have pushed earlier while traversing leftwards*/)
/*n will be hte successor node.
}
in inorder traversal we have number in ascending order in a
binary search tree.
hence the successor always is to the right, if exists,
or one level above.
**Go through the inorder traversal program to get a better
picture.
| Is This Answer Correct ? | 11 Yes | 27 No |
Can the sizeof operator be used to tell the size of an array passed to a function?
When can a far pointer be used?
Main must be written as a.the first function in the program b.Second function in the program c.Last function in the program d.any where in the program
19 Answers CTS, HCL, TCS,
How can I read a directory in a C program?
2 Answers Bright Outdoor, Wipro,
One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.
Switch (i) i=1; case 1 i++; case 2 ++i; break; case 3 --i; Output of i after executing the program
What are register variables? What are the advantage of using register variables?
12345 1234 123 12 1
Is boolean a datatype in c?
How many bytes are occupied by near, far and huge pointers (dos)?
What is the purpose of #pragma directives in C?
Explain logical errors? Compare with syntax errors.