diff --git a/C++/Algorithms/Graph Theory Algorithms/prims.cpp b/C++/Algorithms/Graph Theory Algorithms/prims.cpp new file mode 100644 index 000000000..0a435c4ce --- /dev/null +++ b/C++/Algorithms/Graph Theory Algorithms/prims.cpp @@ -0,0 +1,102 @@ +#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<