Here is the modified version of Morris inorder tree traversal
algorithm<http://stackoverflow.com/questions/5502916/please-explain-morris-inorder-tree-traversal-without-using-stacks-or-recursion>


inordermorrisiterative(Tnode *root) {
    Tnode *current = root, *pred = NULL, *succesor = NULL;

    while (current != NULL) {
        succesor = current->right;
        if (succesor != NULL && current->next==NULL) {
            while (succesor->left != NULL) {
                succesor = succesor->left;
            }
            current->next = succesor;
        }
        if (current->left == NULL) {
            printf(" %d ", current->data);
            current = current->right;
        } else {
            pred = current->left;
            while (pred->right != NULL && pred->right != current) {
                pred = pred->right;
            }

            if (pred->right == NULL) {
                pred->next = current;
                pred->right = current;
                current = current->left;
            } else {
                pred->right = NULL;
                printf(" %d ", current->data);
                current = current->right;
            }
        }
    }}


You can find my complete code here <http://ideone.com/qYKMW>.

Thanks & Regards
Anantha Krishnan


On Tue, Jul 5, 2011 at 7:52 AM, Ashish Goel <ashg...@gmail.com> wrote:

> convert BST into DLL
>
> refer stanford tree recursion problem
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
> On Mon, Jul 4, 2011 at 11:34 PM, Navneet Gupta <navneetn...@gmail.com>wrote:
>
>> Tree has an extra pointer "next" apart from left and right. Objective
>> is to set next pointer to point to node successor in the tree.
>> Following the next pointer, we would be able to produce sorted list.
>>
>> Looking for both a recursive and non-recursive approach.
>>
>> --Navneet
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to