Skip to content

node [terminology]

Terminology

Usage

  • Use for a tree, linked-list, trie, or graph node currently being processed.
  • Prefer it over cur when currentness is less important than the object's node identity.
  • Use cur when walking a linked list and repeatedly advancing the same pointer.
res = []
stack = []
node = root
while stack or node:
    while node:
        stack.append(node)
        node = node.left

    node = stack.pop()
    res.append(node.val)
    node = node.right

See 94. Binary Tree Inorder Traversal.