*a
  *b1
    -c1
    -c2
  -b2int depth = Math.Log(this.TreeView1.Nodes.Count) + 1;//得到二叉树的深度
        for (int i = 2; i <= depth; i++)
        {
             this.TreeView1.                         //想得到c1,c2 
        }高手请赐教!~

解决方案 »

  1.   

    显然你的不一定是二叉树. a下还可以有b3,b4
    public class Node<T>
        {
            Node<T> lChild;
            Node<T> rChild;
            T value;        public Node<T> LChild
            {
                get { return lChild; }
                set { lChild = value; }
            }
            public Node<T> RChild
            {
                get { return rChild; }
                set { rChild = value; }
            }
            public T Value
            {
                get { return this.value; }
                set { this.value = value; }
            }        public T[] DepthTraverse(int requiredDepth)
            {
                Stack<T> stack = new Stack<T>();
                this.DepthTraverse(this, requiredDepth, 0, stack);
                return stack.ToArray();        }
            private void DepthTraverse(Node<T> node, int requiredDepth, int currentDepth, Stack<T> stack)
            {
                if (requiredDepth == currentDepth)
                {
                    stack.Push(node.value);
                }
                else
                {
                    this.DepthTraverse(node.lChild, requiredDepth, currentDepth + 1, stack);
                    this.DepthTraverse(node.rChild, requiredDepth, currentDepth + 1, stack);
                }
            }
        }简单层次遍历算法