Created
July 27, 2018 04:52
-
-
Save domarps/482636066ffe452d8a1557568f6b569e to your computer and use it in GitHub Desktop.
This file contains 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
prev = None | |
def convert(node,head,entered): | |
global prev | |
if node != None: | |
convert(node.left, head,entered) | |
node.left = prev | |
if prev == None: | |
head[0] = node | |
else: | |
prev.right = node | |
head[0].left = node | |
rightchild = node.right | |
node.right = head[0] | |
prev = node | |
convert(rightchild,head,entered) | |
def printInorder(root): | |
if root == None: | |
return | |
printInorder(root.left) | |
print(root.val) | |
printInorder(root.right) | |
def BSTtoLL(node): | |
root = node | |
arr = [None] | |
prev = None | |
convert(root, arr, False) | |
head = arr[0] | |
temp = head | |
result = "" | |
while head != None: | |
result += str(head.val) + " " | |
head = head.right | |
if head == temp: | |
break | |
print(result.strip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment