enh(CPlusPlus): add helps function on kruskal algorithm (#731)
Co-authored-by: Shivam Patel <shivampatel@Shivams-Air.attlocal.net>pull/720/head
parent
e49aea4487
commit
158d8c0d49
|
@ -129,6 +129,14 @@ void KruskalMST(Graph* graph)
|
||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function which takes in src, dest, weight, index, address of graph as an argument
|
||||||
|
// to update the value of graph for respective index
|
||||||
|
void updateGraph(int s, int d, int w, int idx, Graph** graph){
|
||||||
|
graph->edge[idx].src = s;
|
||||||
|
graph->edge[idx].dest = d;
|
||||||
|
graph->edge[idx].weight = w;
|
||||||
|
}
|
||||||
|
|
||||||
// Driver code
|
// Driver code
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -139,29 +147,19 @@ int main()
|
||||||
Graph* graph = createGraph(V, E);
|
Graph* graph = createGraph(V, E);
|
||||||
|
|
||||||
// add edge 0-1
|
// add edge 0-1
|
||||||
graph->edge[0].src = 0;
|
updateGraph(0, 1, 10, 0, &graph);
|
||||||
graph->edge[0].dest = 1;
|
|
||||||
graph->edge[0].weight = 10;
|
|
||||||
|
|
||||||
// add edge 0-2
|
// add edge 0-2
|
||||||
graph->edge[1].src = 0;
|
updateGraph(0, 2, 6, 1, &graph);
|
||||||
graph->edge[1].dest = 2;
|
|
||||||
graph->edge[1].weight = 6;
|
|
||||||
|
|
||||||
// add edge 0-3
|
// add edge 0-3
|
||||||
graph->edge[2].src = 0;
|
updateGraph(0, 3, 5, 2, &graph);
|
||||||
graph->edge[2].dest = 3;
|
|
||||||
graph->edge[2].weight = 5;
|
|
||||||
|
|
||||||
// add edge 1-3
|
// add edge 1-3
|
||||||
graph->edge[3].src = 1;
|
updateGraph(1, 3, 15, 3, &graph);
|
||||||
graph->edge[3].dest = 3;
|
|
||||||
graph->edge[3].weight = 15;
|
|
||||||
|
|
||||||
// add edge 2-3
|
// add edge 2-3
|
||||||
graph->edge[4].src = 2;
|
updateGraph(2, 3, 4, 4, &graph);
|
||||||
graph->edge[4].dest = 3;
|
|
||||||
graph->edge[4].weight = 4;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue