Skip to content

Instantly share code, notes, and snippets.

@aershov24
Created October 13, 2020 05:28
Show Gist options
  • Select an option

  • Save aershov24/5859c3462665b1df01059d2d598b2d6c to your computer and use it in GitHub Desktop.

Select an option

Save aershov24/5859c3462665b1df01059d2d598b2d6c to your computer and use it in GitHub Desktop.
Markdium-12 Recursion Interview Questions (SOLVED) Devs Have To Nail
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