/ Published in: C++
implementation of floyd's algorithm with the dynamic programming in the c++
Expand |
Embed | Plain Text
#include <iostream> #define N 4 using namespace std; int min(int a,int b){ if(a < b) return a; return b; } int main(){ int D[N][N] ={ {0,999,3,999}, {2,0,999,999}, {999,7,0,1}, {6,999,999,0} }; for(int k = 0; k<N; k++) for(int i = 0; i<N; i++) for(int j = 0; j<N; j++) D[i][j] = min(D[i][j], D[i][k]+D[k][j]); cout<<"\nMatrica udaljenosti:\n"; for(int i=0;i<N;i++){ for(int j=0;j<N;j++) cout<<D[i][j]<<" "; cout<<"\n"; } int n; cin >> n; return 0; }
You need to login to post a comment.
