
void path(int i,int j
if(p[j]!=0
path(i,p[j
print(p[j
path(p[j],j
{
if(p[j]!=0
path(i,p[j
print(p[j
path(p[j],j
{
کد اصلی برنامه ای که نوشتم اینه:
#include "iostream.h"
#include "conio.h"
#include "stdio.h"
#include "stdlib.h"
class path {
int n;
int p[10][10];
int a[10][10];
int c[10][10];
public:
void get();
void pm();
void ap();
void disp();
};
void path::get() {
int i,j,k;
cout<<"Enter the number of nodes in the graph :";
cin>>n;
cout<<"Enter the adjacency matrix :<BR>";
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
cout<<"a["<<i<<","<<j<<"] = ";
cin>>a[j];
p[j]=0;
} }
cout<<"Enter The cost matrix is :<BR>";
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
cout<<"a["<<i<<","<<j<<"] = ";
cin>>c[j];
} }
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
p[j]=a[j];
} } }
void path:

cout<<"The output matrix for the given graph is :<BR>";
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
cout<<p[j]<< " ";
}
cout<<endl;
} }
void path:
int i,j,k;
for(k=1;k<=n;k++) {
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
p[j]=p[j] || p[k] && p[k][j];
} } }
}
void path::ap() {
int i,j,k;
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++){
p[j]=c[j];
} }
for(k=1;k<=n;k++) {
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
if(p[j]<p[k]+p[k][j]) {
p[j]=p[j];
} else {
p[j]=p[k]+p[k][j];
} } } } }
void main() {
path p;
p.get();
p.pm();
cout<<"path matrix is :<BR>";;
p.disp();
getch();
p.ap();
cout<<"all pair shortest path matrix is :<BR>";
p.disp();
getch();
}