Zalmoxis Blog Rotating Header Image

Non-Recursive Binary Tree Traverse in C#

private void NonRecursive()        {            TreeNode currNode = root;            while (true)            {                if (currNode == null)                    break;



                if (currNode.Left != null && currNode.Left.Visited != 1)                    currNode = currNode.Left;                else if (currNode.Right != null && currNode.Right.Visited != 1)                    currNode = currNode.Right;                else if (currNode.Visited == 0)                {                    Console.Write(currNode.Value + " ");                    currNode.Visited = 1;                }                else                    currNode =currNode.Parent;            }        }

There is another way using a stack but using a Stack is not so Iterative approach for me.

Popularity: 1% [?]

Related posts:

  1. Sorting Foreign Key Values in Dynamic Data Web Site [...]...
  2. Backing Up From Remote SQL Server to Local Drive [...]...
  3. Сложих Малко Категории [...]...
  4. Reading The Body Fat Solution – Everything You Need For Fat Loss [...]...

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>