I have a questions with regards to a couple of lines in this code. 1. It's "Stack.Push(root)" instead of "result.Add(root)". I get that the root node shall be added to the return array, but I still do not understand why the stack comes out here. 2. And the few lines below 1., it's "result.Add(currentNode.val), instead of "Stack.Push(currentNode.val)". Here I am still confused how the stack and the List have been used interchangeably (or non-interchangeably). 3. The same goes for the line "stack.Push(currentNode.children[i])" , instead of "result.Add(currentNode.val)". Why is the stack push here?
It would be great if anyone could explain to me a bit about those questions.