AlgorithmsNYC/AlgorithmsNYC — pull request #20 by dcordes (2012-05-09 04:35:04+00:00)
Title: C implementation of Prim's algorithm

Andy,

Here's a C implementation of Prim's algorithm. First-time shot. I embedded two graph tests in the code, output is thus, which is correct.

Thanks!

Daniel
~~~~~~~~~~~~~~~~~~~~~~

Matrix:
0 0 1 2 0
0 0 3 0 5
2 3 0 6 4
1 0 6 0 0
0 5 4 0 0
Minimum spanning tree for matrix, from Prim's algorithm:
2 <=====> 1
0 <=====> 2
0 <=====> 3
2 <=====> 4
~~~~~~~~~~~~~~~~~~~~~~~~
Matrix:
0 3 0 0 0 0 6
3 0 0 4 0 0 8
0 1 0 2 10 0 0
0 4 2 0 0 0 5
0 0 10 0 0 8 3
0 0 0 0 8 0 0
6 8 0 5 3 0 0
Minimum spanning tree for matrix, from Prim's algorithm:
0 <=====> 1
3 <=====> 2
1 <=====> 3
6 <=====> 4
4 <=====> 5
3 <=====> 6
~~~~~~~~~~~~~~~~~~~~~~~~