-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.java
More file actions
44 lines (37 loc) · 806 Bytes
/
Graph.java
File metadata and controls
44 lines (37 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.driver;
import java.util.*;
import com.utilities.Dijkastras;
public class Graph {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int n=5;
Scanner sr=new Scanner(System.in);
int [][]graph=new int[n][n];
System.out.println("enter graph");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
graph[i][j]=sr.nextInt();
if(graph[i][j]<=0){
graph[i][j]=999;
}
}
}
for(int i=0;i<n;i++){
Dijkastras.dij(graph, n, i);
}
System.out.println("shortest path graph is: ");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
System.out.print(graph[i][j] +" ");
}
System.out.println();
}
}
}/*0 2 1 0 0
2 0 3 4 0
1 3 0 1 2
0 4 1 0 3
0 0 2 3 0*/