From 8ea07f51ad4ec1e8fb94e7bd2cb8df8d0b09ad38 Mon Sep 17 00:00:00 2001 From: Abdurrezzak Efe Date: Sat, 11 Nov 2017 18:06:58 +0200 Subject: [PATCH] Add files via upload --- 21.PrimAlgorithm.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 21.PrimAlgorithm.cpp 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