22bce7873 Asg7
22bce7873 Asg7
>>WRITE A JAVA PROGRAM TO DISPLAY SHORTEST PATH BETWEEN EVERY PAIR OF NODES.
CODE:
import java.util.Scanner;
A[i][j] = cost[i][j];
if (A[i][k] != INF && A[k][j] != INF && A[i][j] > A[i][k] + A[k][j]) {
V[i][j] = k;
}
if (i != j) {
printPath(V, i, j);
System.out.println(j);
if (V[i][j] == i) return;
printPath(V, i, V[i][j]);
int n = scanner.nextInt();
int[][] cost = new int[n][n];
System.out.println("Enter adjacency matrix (Use " + INF + " for no direct path):");
cost[i][j] = scanner.nextInt();
scanner.close();
allPairs(n, cost);
OUTPUT:
0 3 99999 7
8 0 2 99999
5 99999 0 1
2 99999 99999 0
0 -> 1
0 -> 2 -> 3
0 -> 3
1 -> 2
1 -> 2 -> 3
2 -> 3
3 -> 0