diff --git a/21.PrimAlgorithm.cpp b/21.PrimAlgorithm.cpp new file mode 100644 index 0000000..ce7b800 --- /dev/null +++ b/21.PrimAlgorithm.cpp @@ -0,0 +1,76 @@ +/* + * This program constructs an undirected graph by taking edges and vertices from the user + * and sing Prim's Algorithm + * constructs a Minimum Spanning Tree + * + * Coded by: Abdurrezak Efe + * */ + +#include +#include +using namespace std; + +const int V = 1000; //assumed number of vertices +int edges[V+1][V+1] = {0}; //the graph itself + +int minKeyIndex(int keys[], bool inMST[], int v) //finding the minimum keyed vertex +{ + //finding the vertex with smallest key to add to MST + int minKey = INT_MAX, minIndex=-1; + for(int i=0; i> v >> e; + + //constructing the graph + int x,y,w; + for(int i=0;i> x >> y >> w, edges[x][y] = edges[y][x] = w; + + Prim(v, e); +} \ No newline at end of file