Connecting siblings in binary search tree
<p>I am trying to connect the siblings of the binary search tree. You can find the logic in the Connect() method. My question is, is there any better way to do it? Am I overdoing by using two queues to implement the logic? </p>

<pre><code>using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;

namespace SampleCSParallel
{
    class Tree
    {
        public Tree left = null;
        public Tree right = null;
        public Tree sibling = null;
        public int _data;

        Tree(int data)
        {
            _data = data;
            left = null;
            right = null;
        }

        public Tree Left
        {
            get
            {
                return this.left;
            }
        }

        public Tree Right
        {
            get
            {
                return this.right;
            }
        }

        public Tree AddNode(Tree node, int data)
        {
            if (node == null)
            {
                node = new Tree(data);
                return node;
            }
            else if (node._data &lt;= data)
            {
                node.left = AddNode(node.left, data);
            }
            else if (node._data &gt; data)
            {
                node.right = AddNode(node.right, data);
            }
            return node;
        }

        public static Tree CreateTree(Tree node, int depth, int start)
        {
            if (node == null)
                node = new Tree(start);
            if (depth &gt; 1)
            {
                node.left = CreateTree(node.left, depth - 1, start + 1);
                node.right = CreateTree(node.right, depth - 1, start + 1);
            }
            return node;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            //Tree node = null;
            Tree tr = Tree.CreateTree(null, 4, 1);
            Stopwatch sw = Stopwatch.StartNew();
            int total = WalkTree(tr);           
            TimeSpan ts = sw.Elapsed;
            Console.WriteLine("in {0} sec", ts.Seconds);
            Console.WriteLine("total:{0}", total);
            connect(tr);
            Console.ReadLine();
        }        

        static void connect(Tree root)
        {
            Queue&lt;Tree&gt; nodeQueue = new Queue&lt;Tree&gt;();         
            nodeQueue.Enqueue(root);
            Console.WriteLine(root._data);
            connectSiblings(nodeQueue);
        }

        static void connectSiblings(Queue&lt;Tree&gt; nodeQueue)
        {
            Queue&lt;Tree&gt; childrenQueue = new Queue&lt;Tree&gt;();            
            StringBuilder MsgStr = new StringBuilder();
            bool done = false;

             while (!done)
             {
             while (nodeQueue.Count != 0)
             {

                    Tree parent = nodeQueue.Dequeue();            
              if (parent.left != null)
              {
               childrenQueue.Enqueue(parent.left);
              }
              if (parent.right != null)
              {
               childrenQueue.Enqueue(parent.right);
              }   
             }

                 Tree prevNode = null;
                 Tree currNode = null;
             while (childrenQueue.Count != 0)
             {
                    currNode = childrenQueue.Dequeue();
              nodeQueue.Enqueue(currNode);          

              if (prevNode != null)
              {            
                        MsgStr.Append(string.Format("\t{0}",currNode._data));             
              }
              else
              {
               prevNode = currNode;            
                        MsgStr.Append(string.Format("\t{0}",prevNode._data));
              }   
             }           
                Console.WriteLine(MsgStr.ToString());
             MsgStr.Remove(0, MsgStr.Length);

             if (nodeQueue.Count == 0 &amp;&amp; childrenQueue.Count == 0)
              done = true;
             }
        }
    }  
}
</code></pre>
