diff --git "a/Prim\342\200\231s MST" "b/Prim\342\200\231s MST" new file mode 100644 index 0000000..781a843 --- /dev/null +++ "b/Prim\342\200\231s MST" @@ -0,0 +1,107 @@ +// A C++ program for Prim's Minimum +// Spanning Tree (MST) algorithm. The program is +// for adjacency matrix representation of the graph +#include +using namespace std; + +// Number of vertices in the graph +#define V 5 + +// A utility function to find the vertex with +// minimum key value, from the set of vertices +// not yet included in MST +int minKey(int key[], bool mstSet[]) +{ + // Initialize min value + int min = INT_MAX, min_index; + + for (int v = 0; v < V; v++) + if (mstSet[v] == false && key[v] < min) + min = key[v], min_index = v; + + return min_index; +} + +// A utility function to print the +// constructed MST stored in parent[] +void printMST(int parent[], int graph[V][V]) +{ + cout<<"Edge \tWeight\n"; + for (int i = 1; i < V; i++) + cout<