public List <TreeSortNode <T> > GetAllNodes() { List <TreeSortNode <T> > list = new List <TreeSortNode <T> >(); Stack <TreeSortNode <T> > stack = new Stack <TreeSortNode <T> >(); stack.Push(rootNode); while (stack.Count > 0) { TreeSortNode <T> currentNode = stack.Pop(); foreach (var subNode in currentNode.SubValues) { stack.Push(subNode); } if (currentNode.Values.Count > 0) { list.Add(currentNode); } } return(list); }
public List <T> GetValue(string ident) { char[] keys = ident.ToCharArray(); TreeSortNode <T> node = rootNode; for (int i = 0; i < keys.Length; i++) { bool found = false; for (int y = 0; y < node.SubValues.Count; y++) { if (node.SubValues[y].Name == keys[i]) { node = node.SubValues[y]; found = true; break; } } if (!found) { return(new List <T>()); } } if (null == node) { return(new List <T>()); } return(node.Values); }
public void InsertValue(List <char> ident, T Value) { if (null == subValues) { subValues = new List <TreeSortNode <T> >(); } if (ident.Count == 0) { Values.Add(Value); return; } bool match = false; for (int i = 0; i < subValues.Count; i++) { if (subValues[i].Name == ident[0]) { match = true; ident.RemoveAt(0); subValues[i].InsertValue(ident, Value); break; } } if (!match) { TreeSortNode <T> newNode = new TreeSortNode <T>() { Name = ident[0] }; subValues.Add(newNode); ident.RemoveAt(0); newNode.InsertValue(ident, Value); } }
public System.Collections.IEnumerator GetEnumerator() { Stack <TreeSortNode <T> > stack = new Stack <TreeSortNode <T> >(); stack.Push(rootNode); while (stack.Count > 0) { TreeSortNode <T> currentNode = stack.Pop(); foreach (var subNode in currentNode.SubValues) { stack.Push(subNode); } if (currentNode.Values.Count > 0) { foreach (var value in currentNode.Values) { yield return(value); } } } }