Skip to content

Commit 2649cbd

Browse files
author
huangkui
committed
基本堆操作,堆排序
1 parent 8cfaa5d commit 2649cbd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

php/10_heap/main.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
namespace Algo_10;
3+
4+
require_once '../vendor/autoload.php';
5+
$arr=[50,3,60,70,45,20,100,0,58];
6+
7+
$heap=new Heap();
8+
foreach ($arr as $v){
9+
$heap->insert($v);
10+
}
11+
12+
while(($r=$heap->deleteFirst())!==null){
13+
echo $r." ";
14+
}
15+
echo PHP_EOL;
16+
17+
$heap1=new Heap(10);
18+
19+
foreach ($arr as $v){
20+
$heap1->insertOnly($v);
21+
}
22+
23+
24+
25+
$heap1->heapAll();
26+
//堆化后的
27+
print_r($heap1->dataArr);
28+
//堆排序
29+
$heap1->heapSort();
30+
print_r($heap1->dataArr);

0 commit comments

Comments
 (0)