#include <stdio.h>

#include <limits.h>

#define TRUE 1

#define FALSE 0

#define MAX_VERTICES 7

#define INF 1000


int weight[MAX_VERTICES][MAX_VERTICES] = {

{ 0, 7, INF, INF, 3, 10, INF},

{ 7, 0, 4, 10, 2, 6, INF},

{ INF, 4, 0, 2, INF, INF, INF},

{ INF, 10, 2, 0, 11, 9, 4},

{ 3, 2, INF, 11, 0, INF, 5},

{ 10, 6, INF, 9, INF, 0, INF },

{ INF, INF, INF, 4, 5, INF, 0}};


int distance[MAX_VERTICES];

int found[MAX_VERTICES];


int choose(int distance[], int n, int found[]){

int i, min, minpos;

min = INT_MAX;

minpos = -1;

for( i=0; i<n; i++)

if( distance[i] < min && ! found[i]) {

min = distance[i];

minpos = i;

}

return minpos;

}

//

void shortest_path(int start, int n){

int i, u, w;

for( i=0; i<n; i++){

distance[i] = weight[start][i];

found[i] = FALSE;

}

found[start] = TRUE;

distance[start] = 0;

for( i=0; i<n-1; i++){

u = choose(distance, n, found);

found[u] = TRUE;

for( w=0; w<n; w++)

if(!found[w])

if(distance[u] + weight[u][w]<distance[w])

distance[w] = distance[u] + weight[u][w];

}

}


int main(){

//shortest_path(0, MAX_VERTICES);


return;

}


'이전것 > 개발' 카테고리의 다른 글

체이닝의 구현  (0) 2014.11.20
선형조사법  (0) 2014.11.18
kruskal Greedy Method  (0) 2014.11.06
너비 우선 탐색  (0) 2014.11.06
너비 우선 탬색  (0) 2014.10.28
블로그 이미지

잉비니

,