日期:2011-12-11 浏览次数:20489 次
PHP实现的格鲁斯卡尔算法(kruscal),如下代码:
- <?php
- require 'edge.php';
- $a = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i');
- $b = array('ab'=>'10', 'af'=>'11', 'gb'=>'16', 'fg'=>'17', 'bc'=>'18', 'bi'=>'12', 'ci'=>'8', 'cd'=>'22', 'di'=>'21', 'dg'=>'24', 'gh'=>'19', 'dh'=>'16', 'de'=>'20', 'eh'=>'7','fe'=>'26');
- $test = new Edge($a, $b);
- print_r($test->kruscal());
- ?>
- <?php
- //边集数组的边类
- class EdgeArc{
- private $begin;//起始点
- private $end;//结束点
- private