每个节点给出了父节点及孩子结点列表int parentID;
ArrayList<Integer> chilList;
如何求以任意节点为根节点是树中的节点数?要求不用递归不用栈。

解决方案 »

  1.   

    忘了说了,把所有节点的chilList的size加起来不就行了
      

  2.   

    如果你是oracle的话,可以用oralce自带的函数
      
    子找父
    select   * from   treeTable   a   start   with   id=8   connect   by     id=prior   priorid;   
        
    ---按父找子--   
    select   * from   treeTable   a   start   with   id=1   connect   by   prior   id=priorid; 得到一个集合,判断集合的size就可以知道该节点下的节点数了。
      

  3.   

    又是那个变态老师来考csdn呢……