Return the list of node values in snake order traversal from a given binary tree. For instance:
# Input:
# 1
# 2 3
# 4 5 6 7
# Expected Return:
# [1, 3, 2, 4, 5, 6, 7]
Write a psuedo-code response to fit the following template:
class Node {
def __init__(self, int val, Node left=None, Node right=None) {
self.val = val
self.left = left
self.right = right
}
}
def snake_order(tree) {
# YOUR ANSWER HERE
}
n = array()
n[4] = new Node(4)
n[5] = new Node(5)
n[6] = new Node(6)
n[7] = new Node(7)
n[2] = new Node(2, n[4], n[5])
n[3] = new Node(3, n[6], n[7])
n[1] = new Node(1, n[2], n[3])
print(snake_order(n[1]))
# [1, 3, 2, 4, 5, 6, 7]