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 |
#define f(g,h) g##h main O int i=0 int var=100 ; print f ("%d"f(var,10));} what would be the output?
Which header file is essential for using strcmp function?
Explain how can I pad a string to a known length?
Do string constants represent numerical values?
Why pointers are used?
Reverse a string word by word??
What is the use of a conditional inclusion statement in C?
all c language question
write a c programs to do multiplication of two numbers with out using arithmatic operator ??????????
Can include files be nested? How many levels deep can include files be nested?
What is a dynamic array in c?
main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i]); } what will be the output? }
22 Answers NDS, TCS,