A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d2/d64/prims__minimum__spanning__tree_8cpp_source.html below:

TheAlgorithms/C++: greedy_algorithms/prims_minimum_spanning_tree.cpp Source File

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"

;

int main()

Main function.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4