CN Lab P6
CN Lab P6
Program 6: Write a program to find the shortest path between vertices using bellman-
ford algorithm.
import java.util.Scanner;
private int D[ ];
this.num_ver = num_ver;
D[node] = MAX_VALUE;
D[source] = 0;
if (A[sn][dn] != MAX_VALUE)
if (A[sn][dn] != MAX_VALUE)
int num_ver = 0;
int source;
num_ver = scanner.nextInt( );
A[sn][dn] = scanner.nextInt( );
if (sn == dn)
A[sn][dn] = 0; continue;
if (A[sn][dn] == 0)
A[sn][dn] = MAX_VALUE;
}
Dept of CSE, SMVCE Page 27
Computer Networks Lab [BCS502]
source = scanner.nextInt( );
b.BellmanFordEvaluation(source, A);
scanner.close( );
OUTPUT: