Question: Can you write this code in Pseudo code? the program is written in C language - #include #include struct Node { int Value; struct Node*

Can you write this code in Pseudo code?

the program is written in C language -

#include #include

struct Node { int Value; struct Node* Left; struct Node* Right; struct Node* Parent; }; struct Node * minValue(struct Node* Node); struct Node * inOrderSuccessor(struct Node *Root, struct Node *n) { // step 1 of the above algorithm if( n->Right != NULL ) return minValue(n->Right); // step 2 of the above algorithm struct Node *p = n->Parent; while(p != NULL && n == p->Right) { n = p; p = p->Parent; } return p; }

struct Node * minValue(struct Node* Node) { struct Node* current = Node; // loop down to find the Leftmost leaf while (current->Left != NULL) { current = current->Left; } return current; } //Helper function that allocates a new Node with the given Value and NULL Left and Right pointers struct Node* newNode(int Value) { struct Node* Node = (struct Node*)malloc(sizeof(struct Node)); Node->Value = Value; Node->Left = NULL; Node->Right = NULL; Node->Parent = NULL; return(Node); } //function for insertion struct Node* insert(struct Node* Node, int Value) { //in case of empty tree if (Node == NULL) return(newNode(Value)); else { struct Node *temp; // Otherwise, recursion on down the tree if (Value <= Node->Value) { temp = insert(Node->Left, Value); Node->Left = temp; temp->Parent= Node; } else { temp = insert(Node->Right, Value); Node->Right = temp; temp->Parent = Node; } //returning unchanged pointer to access all of the Nodes return Node; } } int main() { struct Node* Root = NULL, *temp, *succ, *min; //creating the tree given in the above diagram Root = insert(Root, 20); Root = insert(Root, 8); Root = insert(Root, 22); Root = insert(Root, 4); Root = insert(Root, 12); Root = insert(Root, 10); Root = insert(Root, 14); temp = Root->Left->Right->Right; succ = inOrderSuccessor(Root, temp); if(succ != NULL) { printf(" Inorder Successor of %d is %d ", temp->Value, succ->Value); } else { printf(" Inorder Successor doesn't exist "); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!