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++; } }
public void AddNode(TreeNode newNode) { this.NodeList.Add(newNode); }