7int graph[V][V] = {{0, 5, 1, 2}, {5, 0, 3, 3}, {1, 3, 0, 4}, {2, 3, 4, 0}};
18 for (
int i = 0; i < V; i++) {
19 MST_Array[i].visited =
false;
20 MST_Array[i].key = INFINITY;
21 MST_Array[i].near = i;
28 for (
int v = 0; v < V; v++) {
31 for (
int i = 0; i < V; i++) {
32 if (MST_Array[i].key < min && MST_Array[i].visited ==
false &&
33 MST_Array[i].key != INFINITY) {
34 min = MST_Array[i].key;
39 MST_Array[minIndex].visited =
true;
41 for (
int i = 0; i < V; i++) {
42 if (
graph[minIndex][i] != 0 &&
graph[minIndex][i] < INFINITY) {
43 if (
graph[minIndex][i] < MST_Array[i].key) {
44 MST_Array[i].key =
graph[minIndex][i];
45 MST_Array[i].near = minIndex;
53 for (
int i = 0; i < V; i++) {
54 cout << i <<
" - " << MST_Array[i].near <<
"\t"
55 <<
graph[i][MST_Array[i].near] <<
"\n";