Ejemplo n.º 1
0
        private List <Block> GetNodePath(BlockNode block)
        {
            Stack <BlockNode> st = new Stack <BlockNode>();

            if (!GetPath(_root, block.block, ref st))
            {
                return(null);
            }
            List <Block>     blockList = new List <Block>();
            List <BlockNode> list      = new List <BlockNode>(st.ToArray());

            foreach (BlockNode node in list)
            {
                blockList.Add(node.block);
            }
            return(blockList);
        }
Ejemplo n.º 2
0
 private bool GetPath(BlockNode root, Block node, ref Stack <BlockNode> stack)
 {
     if (null == root)
     {
         return(false);
     }
     if (root.block.ID == node.ID)
     {
         stack.Push(root);
         return(true);
     }
     if (GetPath(root.Normal, node, ref stack) || GetPath(root.Reverse, node, ref stack))
     {
         stack.Push(root);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
 //找到二叉树的叶子节点,叶子节点的normal和reverse方向节点都为空
 private void GetLeafNode(BlockNode node, List <BlockNode> list)
 {
     if (null == node.Normal && null == node.Reverse)
     {
         list.Add(node);
     }
     else
     {
         if (null != node.Normal)
         {
             GetLeafNode(node.Normal, list);
         }
         if (null != node.Reverse)
         {
             GetLeafNode(node.Reverse, list);
         }
     }
 }
Ejemplo n.º 4
0
        private void Add(BlockNode parent)
        {
            int signalId = this.GetBlockSignal(parent.block, _dir);

            if (0 == signalId || _id == signalId)
            {
                if (_dir == Sys.Up)
                {
                    int nextId = parent.block.NextUpNBlockId;
                    if (0 != nextId)
                    {
                        Block nBlock = (Block)Sys.GetNode(nextId, _sydb.blockInfoList.Cast <Basic>().ToList());
                        parent.Normal = new BlockNode(nBlock);
                        Add(parent.Normal);
                    }
                    nextId = parent.block.NextUpRBlockId;
                    if (0 != nextId)
                    {
                        Block nBlock = (Block)Sys.GetNode(nextId, _sydb.blockInfoList.Cast <Basic>().ToList());
                        parent.Reverse = new BlockNode(nBlock);
                        Add(parent.Reverse);
                    }
                }
                else
                {
                    int nextId = parent.block.NextDnNBlockId;
                    if (0 != nextId)
                    {
                        Block nBlock = (Block)Sys.GetNode(nextId, _sydb.blockInfoList.Cast <Basic>().ToList());
                        parent.Normal = new BlockNode(nBlock);
                        Add(parent.Normal);
                    }
                    nextId = parent.block.Next_Down_Reverse_Block_ID;
                    if (0 != nextId)
                    {
                        Block nBlock = (Block)Sys.GetNode(nextId, _sydb.blockInfoList.Cast <Basic>().ToList());
                        parent.Reverse = new BlockNode(nBlock);
                        Add(parent.Reverse);
                    }
                }
            }
        }