Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
                    }
                }
            }
        }