Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Write a routine to reconstruct the shortest paths from the algorithm i.docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité

Consultez-les par la suite

1 sur 2 Publicité

Write a routine to reconstruct the shortest paths from the algorithm i.docx

Télécharger pour lire hors ligne

Write a routine to reconstruct the shortest paths from the algorithm in the Textbook, Section 10.3.4.
Solution
public static void allPair(in[][] a, int[][] d, int[][] paths)
{
int len = a.length;
int index = 0,q=0,r;
while(index<len)
{
while(q<len)
{
d[index][q] = a[index][q];
paths[index][q] = NOT_A_VERTEX;
q++;;
}
index++;
}

while(r<len)
{
while(index<len)
{
while(q<len)
{
if(d[index][r] + d[r][q] < d[index][q] )
{
d[index][q] = d[index][r] + d[r][q];
paths[index][q] = r;
q++;
}
index++;
}
r++
}
}
}
.

Write a routine to reconstruct the shortest paths from the algorithm in the Textbook, Section 10.3.4.
Solution
public static void allPair(in[][] a, int[][] d, int[][] paths)
{
int len = a.length;
int index = 0,q=0,r;
while(index<len)
{
while(q<len)
{
d[index][q] = a[index][q];
paths[index][q] = NOT_A_VERTEX;
q++;;
}
index++;
}

while(r<len)
{
while(index<len)
{
while(q<len)
{
if(d[index][r] + d[r][q] < d[index][q] )
{
d[index][q] = d[index][r] + d[r][q];
paths[index][q] = r;
q++;
}
index++;
}
r++
}
}
}
.

Publicité
Publicité

Plus De Contenu Connexe

Plus par drosa1 (20)

Plus récents (20)

Publicité

Write a routine to reconstruct the shortest paths from the algorithm i.docx

  1. 1. Write a routine to reconstruct the shortest paths from the algorithm in the Textbook, Section 10.3.4. Solution public static void allPair(in[][] a, int[][] d, int[][] paths) { int len = a.length; int index = 0,q=0,r; while(index<len) { while(q<len) { d[index][q] = a[index][q]; paths[index][q] = NOT_A_VERTEX; q++;; } index++; } while(r<len) { while(index<len) { while(q<len) { if(d[index][r] + d[r][q] < d[index][q] ) { d[index][q] = d[index][r] + d[r][q]; paths[index][q] = r; q++; }
  2. 2. index++; } r++ } } }

×