Last active
October 30, 2020 07:16
-
-
Save nikhilc2710/89c52850b12b5b9e9b24c041a875310d 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
def preorder(root,visited): | |
if root: #check if node exits | |
visited.append(root.data) #append node value to visted stack (V) | |
visited=preorder(root.left,traversal) #go to left subtree (L) | |
visited=preorder(root.right,traversal) #go to right subtree (R) | |
return visited #return visited stack | |
preorder(root,[]) #call preorder function with visited stack |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment