Created
October 13, 2020 05:28
-
-
Save aershov24/5859c3462665b1df01059d2d598b2d6c to your computer and use it in GitHub Desktop.
Markdium-12 Recursion Interview Questions (SOLVED) Devs Have To Nail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void BinaryTreeToDLL(Node root) { | |
| if (root == null) | |
| return; | |
| BinaryTreeToDLL(root.left); | |
| if (prev == null) { // first node in list | |
| head = root; | |
| } else { | |
| prev.right = root; | |
| root.left = prev; | |
| } | |
| prev = root; | |
| BinaryTreeToDLL(root.right); | |
| if (prev.right == null) { // last node in list | |
| head.left = prev; | |
| prev.right = head; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment