In: Computer Science
Please ready a program should output Inorder Tree Traversal
without recursion and without stack!, output in ALGOL W programming
only. Thumbs down for wrong answers
Make a program to perform Heap Sort, must run in Alice programming
only. Only correct answers needed should be in given language
1. Initialize current as root 2. While current is not NULL If the current does not have left child a) Print current’s data b) Go to the right, i.e., current = current->right Else a) Make current as the right child of the rightmost node in current's left subtree b) Go to this left child, i.e., current = current->left
void MorrisTraversal(struct tNode* root)
{
struct tNode *current, *pre;
if (root == NULL)
return;
current = root;
while (current != NULL) {
if (current->left == NULL) {
printf("%d ", current->data);
current = current->right;
}
else {
pre = current->left;
while (pre->right != NULL && pre->right != current)
pre = pre->right;
if (pre->right == NULL) {
pre->right = current;
current = current->left;
}
else {
pre->right = NULL;
printf("%d ", current->data);
current = current->right;
}
}
}
}