solutions
  • solutions
  • Valid Palindrome
  • String to Integer (atoi)
  • addBinary
  • Longest Palindromic Substring
  • Regular Expression Matching
  • Valid Number
  • Count and say
  • Valid anagram
  • Simplify Path
  • Length of last word
  • Longest Valid Parentheses
  • Valid Parentheses
  • Largest Rectangle in Histogram
  • Evaluate Reverse Polish Notation
    • Morris 算法介绍
  • Binary Tree Preorder Traversal
    • //stack
    • //morris
  • Binary Tree Inorder Traversal
    • //stack
    • //morris
  • Binary Tree Postorder Traversal
    • //stack
  • Binary Tree Level Order Traversal
    • 递归
    • 迭代
  • Binary Tree Zigzag Level Order Traversal
    • 递归
    • 迭代
  • Recover Binary Search Tree
    • Recursive
    • morris
  • Same Tree
  • Symmetric Tree
    • Recursive
    • Iterative
  • Balanced Binary Tree
  • Flatten Binary Tree to Linked List
    • Iterative and recursive
  • Populating Next Right Pointers in Each Node II
    • Iterative
    • Recursive
  • Construct Binary Tree from Preorder and Inorder Traversal
  • Construct Binary Tree from Inorder and Postorder Traversal
  • Unique Binary Search Trees
  • Validate Binary Search Tree
  • Convert Sorted Array to Binary Search Tree
  • Convert Sorted List to Binary Search Tree
  • Minimum Depth of Binary Tree
  • Maximum Depth of Binary Tree
  • Path Sum
  • Path Sum II
  • Binary Tree Maximum Path Sum
  • Populating Next Right Pointers in Each Node
  • Sum Root to Leaf Numbers
  • Merge Sorted Array
  • Merge Two Sorted Lists
    • cpp
    • java
  • Merge k Sorted Lists
    • Priority queue
    • merge sort
  • Insertion Sort List
  • Sort List
  • First Missing Positive
  • Sort Colors
  • Search for a Range
  • Search Insert Position
    • Recursive
    • Iterative
  • Search a 2D Matrix
  • *string 的子集(bit)
  • Subsets
    • Bit
    • Recursive
    • Iterative
  • Subsets II
    • Recursive
    • Iterative
  • Permutations
  • Permutations II
    • Java
  • CPP
  • Combinations
    • Recursive
  • Iterative
  • Letter Combinations of a Phone Number
    • Recursive
  • BFS VS DFS
  • Word Ladder
    • Java
Powered by GitBook
On this page

Was this helpful?

  1. Evaluate Reverse Polish Notation

Morris 算法介绍

PreviousEvaluate Reverse Polish NotationNextBinary Tree Preorder Traversal

Last updated 5 years ago

Was this helpful?

算法伪码:

MorrisInOrder():

while 没有结束

如果当前节点没有左后代

 访问该节点

 转向右节点

否则

 找到左后代的最右节点,且使最右节点的右指针指向当前节点

 转向左后代节点

C++实现:

void bst_morris_inorder(struct bst_node *root) {

struct bst_node p = root, tmp;

while (p) {

   if (p->left == NULL) {  

       printf("%d ", p->key);  

       p = p->right;  

   }  

   else {  

       tmp = p->left;  

       while (tmp->right != NULL && tmp->right != p)  

           tmp = tmp->right;  

       if (tmp->right == NULL) {  

           tmp->right = p;  

           p = p->left;  

       }  

       else {  

           printf("%d ", p->key);  

           tmp->right = NULL;  

           p = p->right;  

       }  

   }  

}

}

http://blog.csdn.net/mxw976235955/article/details/39829973
http://www.tuicool.com/articles/zA7NJbj