示例#1
0
文件: Tree.cs 项目: akhilp/cleanshirt
        private void WriteToTree(TreeNode node, string value, int index, String payload)
        {
            value = value.ToLower();
            int size = value.Count();

            while (index < size)
            {

                TreeNode nextNode = node.Contains(value[index]);

                //Continue down the list
                if (nextNode != null && index != size - 1)
                {
                    node = nextNode;
                }
                //At the end. Add node here
                else if(nextNode != null && index == size - 1)
                {
                    nextNode.payload = payload;
                    _count++;
                }
                //At the end and new node
                else
                {
                    TreeNode newNode = new TreeNode();
                    newNode.Character = value[index];
                    if (index == size - 1)
                    {
                        newNode.payload = payload;
                        _count++;
                    }
                    node.AddNode(newNode);
                    node = newNode;
                }

                index++;
            }
        }
示例#2
0
 public void AddNode(TreeNode newNode)
 {
     this.NodeList.Add(newNode);
 }