diff --git a/animations/trees/morris/morrisPostOrder.html b/animations/trees/morris/morrisPostOrder.html index bfae653..5bc5b37 100644 --- a/animations/trees/morris/morrisPostOrder.html +++ b/animations/trees/morris/morrisPostOrder.html @@ -22,7 +22,7 @@ padding: 15px; width: 48%; overflow-y: auto; - height: 88vh; + height: 87vh; font-size: 15px; } @@ -43,12 +43,21 @@ min-width: 30px; } + .code-line { + display: block; + width: 100%; + } + + .code-line.highlighted { + background-color: #ffeb3b; + } + .tree-container { background-color: #f0f0f0; border-radius: 10px; padding: 15px; width: 48%; - height: 88vh; + height: 80vh; position: relative; display: flex; flex-direction: column; @@ -134,56 +143,11 @@
This animation shows how the Morris post-order traversal algorithm works without using a stack or recursion. Click the "Next Step" button to run the animation.
+This animation shows how the Morris post-order traversal algorithm works without using a stack or recursion. Click the "Next Step" button to run the animation step by step.
0. void postorderTraversal(TreeNode* root) {
-1. TreeNode* current = root;
-2. TreeNode* rightmost;
-3. while (current != nullptr) {
-4. if (current->left != nullptr) {
-5. rightmost = current->left;
-6. while (rightmost->right != nullptr && rightmost->right != current) {
-7. rightmost = rightmost->right;
-8. }
-9. if (rightmost->right == nullptr) {
-10. rightmost->right = current;
-11. current = current->left;
-12. } else {
-13. rightmost->right = nullptr;
-14. reverseTraverseRightEdge(current->left);
-15. current = current->right;
-16. }
-17. } else {
-18. current = current->right;
-19. }
-20. }
-21. reverseTraverseRightEdge(root); // final right edge
-22. return;
-23. }
-24.
-25. TreeNode* reverse(TreeNode* head) {
-26. TreeNode* prev = nullptr;
-27. TreeNode* next = nullptr;
-28. while (head != nullptr) {
-29. next = head->right;
-30. head->right = prev;
-31. prev = head;
-32. head = next;
-33. }
-34. return prev;
-35. }
-36.
-37. void reverseTraverseRightEdge(TreeNode* head) {
-38. TreeNode* tail = reverse(head);
-39. TreeNode* current = tail;
-40. while (current != nullptr) {
-41. std::cout << current->val << " ";
-42. current = current->right;
-43. }
-44. reverse(tail); // restore structure
-45. }
+