Exemplo n.º 1
0
        ///<summary>Возвращает итератор, перечисляющий элементы индексатора
        ///IndexEntry</summary>
        public IEnumerator <Leaf> GetEnumerator()
        {
            CSharpDataStructures.Structures.Lists.LinkedList <Leaf> E =
                new CSharpDataStructures.Structures.Lists.LinkedList <Leaf>();
            STACK S = new STACK();

            S.Push(_tree);
            while (!S.IsEmpty())
            {
                Object b = S.Top();
                S.Pop();
                LinkedDictionary <Char, Object> children = (LinkedDictionary <Char, Object>)b;

                ICollection <Char> keys = children.Keys;
                foreach (Char k in keys)
                {
                    if (k == '$')
                    {
                        continue;
                    }
                    S.Push(children.GetValue(k));
                }
                if (children.ContainsKey('$') && children.GetValue('$') != null)
                {
                    E.add((Leaf)children.GetValue('$'));
                }
            }
            return(E.GetEnumerator());
        }
Exemplo n.º 2
0
 private void __init()
 {
     for (Int32 i = 0; i < _adj.Length; i++)
     {
         _adj[i] = new CSharpDataStructures.Structures.Lists.LinkedList <Node <T> >();
     }
     for (Int32 i = 1; i < _adj.Length + 1; i++)
     {
         _adj[i - 1].Add(new GraphNode <T>()
         {
             Name = i.ToString(), Weight = Double.MaxValue
         });
     }
 }
Exemplo n.º 3
0
        //Deikstra Shortest paths from vertex.
        public CSharpDataStructures.Structures.Lists.LinkedList <Int32> DSP(Int32 vertex)
        {
            CSharpDataStructures.Structures.Lists.LinkedList <Int32> paths = new  CSharpDataStructures.Structures.Lists.LinkedList <Int32>();
            Double[] D = new Double[_n];
            Int32[]  P = new Int32[_n];
            ArrayHeap <GraphNode <T> > Q = new ArrayHeap <GraphNode <T> >(x => x.Weight);

            for (Int32 i = vertex + 1; i <= _n; i++)
            {
                D[i - 1] = ((GraphNode <T>)_adj[0][i]).Weight;
                Q.Add((GraphNode <T>)_adj[i - 1][1]);
            }


            for (Int32 i = 1; i < _n; i++)
            {
                GraphNode <T> w = Q.DeleteMin();
                Int32         vi;
                Int32         wi;
                if (Int32.TryParse(w.Name, out wi))
                {
                    foreach (GraphNode <T> v in Q)
                    {
                        if (Int32.TryParse(v.Name, out vi))
                        {
                            if (D[wi - 1] + v.Weight < D[vi - 1])
                            {
                                P[vi - 1] = wi;
                                D[vi - 1] = D[wi - 1] + v.Weight;
                            }
                        }
                    }
                }
            }
            paths.Add(_n - 1);
            for (Int32 j = _n - 1; j > 1; j = P[j])
            {
                paths.Add(P[j]);
            }

            return(paths);
        }