Exemplo n.º 1
0
        /// <summary>
        /// 查找节点
        /// </summary>
        /// <param name="dfaNode">父节点</param>
        /// <param name="c">字符</param>
        /// <returns>结果</returns>
        private static DFANode FindNode(DFANode dfaNode, char c)
        {
            var nodes = dfaNode.Nodes;

            for (var i = 0; i < nodes.Count; i++)
            {
                var n = nodes[i];
                if (n.Char == c)
                {
                    return(n);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 插入节点
        /// </summary>
        /// <param name="dfaNode">父节点</param>
        /// <param name="cs">字符数组</param>
        /// <param name="index">索引</param>
        private static void InsertNode(DFANode dfaNode, char[] cs, int index)
        {
            var item = FindNode(dfaNode, cs[index]);

            if (item == null)
            {
                item = new DFANode(cs[index]);
                dfaNode.Nodes.Add(item);
            }

            if (index == (cs.Length - 1))
            {
                item.Flag = 1;
            }

            index++;
            if (index < cs.Length)
            {
                InsertNode(item, cs, index);
            }
        }