Skip to content

Instantly share code, notes, and snippets.

@domarps
Created July 27, 2018 04:52
Show Gist options
  • Save domarps/482636066ffe452d8a1557568f6b569e to your computer and use it in GitHub Desktop.
Save domarps/482636066ffe452d8a1557568f6b569e to your computer and use it in GitHub Desktop.
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