Example #1
0
        public void exchange(int i, int j)
        {
            NodeD temp = nodeList[i];

            nodeList[i] = nodeList[j];
            nodeList[j] = temp;
        }
Example #2
0
        public List <int> Dijkstra(ref int[] pi, ref List <NodeD> G, int s)
        {
            InitializeSingleSource(ref pi, ref G, s);

            List <int>    S = new List <int>();
            PriorityQueue Q = new PriorityQueue(G);

            Q.buildHeap();

            while (Q.size() != 0)
            {
                NodeD u = Q.extractMin();

                S.Add(u.ID);

                for (int i = 0; i < u.Adjacency.Count; i++)
                {
                    NodeD v = u.Adjacency[i];
                    int   w = u.Weights[i];

                    Relax(ref pi, u, ref v, w);
                }
            }

            return(S);
        }
Example #3
0
 void Relax(ref int[] pi, NodeD u, ref NodeD v, int w)
 {
     if (v.Distance > u.Distance + w)
     {
         v.Distance = u.Distance + w;
         pi[v.ID]   = u.ID;
     }
 }
Example #4
0
        int heapSearch(NodeD node)
        {
            for (int i = 0; i < heapSize; i++)
            {
                NodeD aNode = nodeList[i];

                if (node.ID == aNode.ID)
                {
                    return(i);
                }
            }

            return(-1);
        }
Example #5
0
 public int find(NodeD node)
 {
     return(heapSearch(node));
 }