C++ implementation of Prim's spanning tree algorithm
kw.cpp
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program for the Prim's algorithm ——————————————————————————————————————————— Enter the total number of nodes 6 Enter the distance of edges 0 6 11 2 0 2 6 0 4 7 0 3 11 4 0 2 0 6 2 7 2 0 9 1 0 0 0 9 0 14 2 3 6 1 14 0 Adjacency matrix is 0 6 11 2 0 2 6 0 4 7 0 3 11 4 0 2 0 6 2 7 2 0 9 1 0 0 0 9 0 14 2 3 6 1 14 0 Edge 3-5 Having Distance 1 Edge 3-0 having distance 2 Edge 3-2 having distance 2 Edge 5-1 having distance 3 Edge 3-4 having distance 9 Total cost is 17 kodingwindow@kw:~$
What Next?
Applications of Data Structures
Advertisement