The TransCompilator

Solved LeetCode program · 428 of 1,000

#0589 · N-ary Tree Preorder Traversal

Easy Depth-First Search chunk-09.md

Original English source

Keep a shared values holding 1, 3, 2, 4, 5, and 6. Keep a shared firstchild holding 1, 4, -1, -1, -1, and -1. Keep a shared nextsibling holding -1, 2, 3, -1, 5, and -1. Keep a shared order as an empty list of whole numbers.

To gather from node (a whole number). If node is less than 0, return. Place item node of values into order. The child is item node of firstchild.
Repeat while child is at least 0.
Gather from child. Set child to item child of nextsibling.

Gather from 0. For each value in order, show value.

Open in Playground Browse all 1,000 problems

Expected stdout

1
3
5
6
2
4