基本堆操作,堆排序
This commit is contained in:
parent
8cfaa5d6d8
commit
2649cbda82
30
php/10_heap/main.php
Normal file
30
php/10_heap/main.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Algo_10;
|
||||
|
||||
require_once '../vendor/autoload.php';
|
||||
$arr=[50,3,60,70,45,20,100,0,58];
|
||||
|
||||
$heap=new Heap();
|
||||
foreach ($arr as $v){
|
||||
$heap->insert($v);
|
||||
}
|
||||
|
||||
while(($r=$heap->deleteFirst())!==null){
|
||||
echo $r." ";
|
||||
}
|
||||
echo PHP_EOL;
|
||||
|
||||
$heap1=new Heap(10);
|
||||
|
||||
foreach ($arr as $v){
|
||||
$heap1->insertOnly($v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$heap1->heapAll();
|
||||
//堆化后的
|
||||
print_r($heap1->dataArr);
|
||||
//堆排序
|
||||
$heap1->heapSort();
|
||||
print_r($heap1->dataArr);
|
Loading…
Reference in New Issue
Block a user