public void exchange(int i, int j) { NodeD temp = nodeList[i]; nodeList[i] = nodeList[j]; nodeList[j] = temp; }
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); }
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; } }
int heapSearch(NodeD node) { for (int i = 0; i < heapSize; i++) { NodeD aNode = nodeList[i]; if (node.ID == aNode.ID) { return(i); } } return(-1); }
public int find(NodeD node) { return(heapSearch(node)); }