Wharshall's Path

#include<iostream>
#include<conio.h>
#define INFINITY ((1 << (8*sizeof (int) - 6)) - 4)
using namespace std;
int main()
{
int a[4][4],b[4][4];
int i,j,k;
cout<<"Enter value of Adjacent Matrix (row wise) :\n";
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{cout<<"\t";
cin>>a[i][j];
}

for(i=0;i<4;i++)
for(j=0;j<4;j++)
{if(a[i][j]==0)
b[i][j]=INFINITY;
else
b[i][j]=a[i][j];
}
for(k=0;k<4;k++)
{
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(b[i][j]>(b[i][k]+b[k][j]))
b[i][j]=(b[i][k]+b[k][j]);
}
}
}
cout<<"\n\nWharshall's Path\n";
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
cout<<b[i][j]<<"\t";
cout<<"\n";
}
getch();
return 0;
}


Popular posts from this blog

Shutdown Pc

Ellipse using OpenGl

String Comparisons