MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / Graph

Class Graph

Programs/Dijkstra.java:65–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64
65class Graph{
66 int v;
67 List<ArrayList<AdjNode>> adjList;
68 Graph(int v){
69 this.v = v;
70 adjList = new ArrayList<>();
71 for(int i = 0; i < this.v; i++){
72 adjList.add(new ArrayList<>());
73 }
74 }
75
76 public void addEdge(int u, int v, int cost){
77 this.adjList.get(u).add(new AdjNode(u, v, cost));
78 this.adjList.get(v).add(new AdjNode(v, u, cost));
79 }
80 public void printGraph(){
81 for(int i = 0 ; i < this.v ; i++){
82 System. out.print(i + " -> ");
83 for(int j = 0 ; j < adjList.get(i).size(); j++){
84 System.out.print(adjList.get(i).get(j).dest + " ");
85 }
86 System. out.println();
87 }
88 }
89}
90
91class AdjNode{
92 int source, dest, cost;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected