Question

In: Computer Science

Please ready a program should output Inorder Tree Traversal without recursion and without stack!, output in...

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

Solutions

Expert Solution

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;

            }

        }

    }

}

  


Related Solutions

Traversal tree program
Traversal tree program
Tree Reconstruction - Pre+In => Post (C++) Give you pre-order traversal and in-order traversal, please output...
Tree Reconstruction - Pre+In => Post (C++) Give you pre-order traversal and in-order traversal, please output post-order traversal. Input Two lines. Pre-order traversal and in-order traversal. Output Post-order traversal. Sample Input GDAFEMHZ ADEFGHMZ Sample Output AEFDHZMG
Traversal tree program in c/c++
Traversal tree program in c/c++
C program that demonstrate tree traversal. see for the sample output. Sample Output: How many node...
C program that demonstrate tree traversal. see for the sample output. Sample Output: How many node do you have in your tree : 5 Enter root: 20 if you want to add to the left press 0 otherwise press 1 answer: 0 Enter next node: 10 if you want to add to the left press 0 otherwise press 1 answer: 0 Enter next node: 8 if you want to add to the left press 0 otherwise press 1 answer: 0...
Modifying the tree traversal C program shown below to do reversed tree traversal as defined below....
Modifying the tree traversal C program shown below to do reversed tree traversal as defined below. Reversed PreOrder: Root, Right, Left. Reversed InOrder:     Right, Root, Left. Reversed PostOrder: Right, Left, Root. The tree is: Root = 1, Left(1) = -2, Right(1) = -3; Left(-2) = 4, Right(-2) = 5; Left(-3) = 6, Right(-3)= 7; Left(5) = -8, Right(5)= -9; Left(7) = 10, Right(7) = 11; Left(11) = -12, Right(11) = -13; Left(-13) = 14. Your program should output the printed...
use postorder and inorder tree traversals to make preorder traversal. #!/usr/bin/env python3 # encoding: UTF-8 """Turning...
use postorder and inorder tree traversals to make preorder traversal. #!/usr/bin/env python3 # encoding: UTF-8 """Turning in-order and post-order tree traversals into pre-order""" def get_preorder(inorder: str, postorder: str) -> str: """Return pre-order traversal of a tree based on its in-order and post-order traversals""" #Complete the following function #raise NotImplementedError
Write a C program that demonstrate tree traversal. A. first is to ask the user to...
Write a C program that demonstrate tree traversal. A. first is to ask the user to enter data B. ask how many nodes THIS IS JUST A SAMPLE. PLEASE ANSWER IT IN COMPLETE CODE. See for the sample output. Sample Output: How many node do you have in your tree : 5 Enter root: 20 if you want to add to the left press 0 otherwise press 1 answer: 0 Enter next node: 10 if you want to add to...
Write a program in python that implements quicksort, first using recursion and then without recursion.
Write a program in python that implements quicksort, first using recursion and then without recursion.
Tree Traversals It should be noted that, in class, all traversal methods were written as recursive...
Tree Traversals It should be noted that, in class, all traversal methods were written as recursive algorithm (i.e. at some point, the method called itself). It is possible to implement non-recursive versions of preorder, inorder, and postorder traversal methods mentioned in class. One intuitive way is by using a stack. 1) Give written pseudocode/explanation of : a) How to build the tree such that a given non-recursive traversal method can be used. b) Your algorithm for a non-recursive preorder, inorder,...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT