4

Modify a binary tree to get preorder traversal using right pointers only

 2 years ago
source link: https://www.geeksforgeeks.org/videos/modify-a-binary-tree-to-get-preorder-traversal-using-right-pointers-only/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Modify a binary tree to get preorder traversal using right pointers only

Modify a binary tree to get preorder traversal using right pointers only
  • 02/06/2022

Given a binary tree. Modify it in such a way that after modification you can have a preorder traversal of it using only the right pointers. During modification, you can use right as well as left pointers. One needs to make the right pointer of root point to the left subtree. If the node has just left child, then just moving the child to right will complete the processing for that node. If there is a right child too, then it should be made right child of the right-most of the original left subtree. The above function used in the code process a node and then returns the rightmost node of the transformed subtree.

Modify a binary tree to get preorder traversal using right pointers only: https://www.geeksforgeeks.org/modify-binary-tree-get-preorder-traversal-using-right-pointers/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK