MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / shortPath

Method shortPath

Leetcode/Java/DijsktraAlgo.java:63–82  ·  view source on GitHub ↗
(ArrayList<Edge>[] graph,int src)

Source from the content-addressed store, hash-verified

61 }
62
63 public static void shortPath(ArrayList<Edge>[] graph,int src){
64 boolean []flag=new boolean[graph.length] ;
65
66 PriorityQueue<Pair> pq = new PriorityQueue<>();
67 pq.add(new Pair(src,""+src,0)) ;
68
69 while(pq.size()>0){
70 Pair top=pq.remove() ;
71 if(flag[top.vtx]) continue ;
72 flag[top.vtx]=true ;
73 System.out.println(top.vtx+" via "+top.path+" @ "+top.wt) ;
74 for(Edge e:graph[top.vtx]){
75 if(!flag[e.nbr]) pq.add(new Pair(e.nbr,top.path+e.nbr,top.wt+e.wt)) ;
76 }
77
78 }
79
80
81
82 }
83}

Callers 1

mainMethod · 0.95

Calls 3

addMethod · 0.80
sizeMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected