Sollicitatievraag bij Microsoft

using recursion to traverse a binary tree

Antwoord op sollicitatievraag

Anoniem

7 jan 2013

Here is three way to traverse the binary tree: private void InOrder(Node localRoot) { if (localRoot != null) { InOrder(localRoot.LeftChild); localRoot.Display(); InOrder(localRoot.RightChild); } } private void PostOrder(Node localRoot) { if (localRoot != null) { PostOrder(localRoot.LeftChild); PostOrder(localRoot.RightChild); localRoot.Display(); } } public void InOrderNth(Node localRoot, int n) { if (localRoot != null) { InOrderNth(localRoot.LeftChild, n); if (n == 0) localRoot.Display(); InOrderNth(localRoot.RightChild, n); } }