mirror of
https://github.com/php/php-src.git
synced 2024-12-04 23:34:25 +08:00
45 lines
535 B
PHP
45 lines
535 B
PHP
--TEST--
|
|
SPL: SplHeap: comparison callback
|
|
--FILE--
|
|
<?php
|
|
class myHeap extends SplHeap {
|
|
public function compare($a, $b) {
|
|
if ($a > $b) {
|
|
$result = 1;
|
|
} else if ($a < $b) {
|
|
$result = -1;
|
|
} else {
|
|
$result = 0;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
$h = new myHeap;
|
|
|
|
$in = range(0,10);
|
|
shuffle($in);
|
|
foreach ($in as $i) {
|
|
$h->insert($i);
|
|
}
|
|
|
|
foreach ($h as $out) {
|
|
echo $out."\n";
|
|
}
|
|
?>
|
|
===DONE===
|
|
<?php exit(0); ?>
|
|
--EXPECTF--
|
|
10
|
|
9
|
|
8
|
|
7
|
|
6
|
|
5
|
|
4
|
|
3
|
|
2
|
|
1
|
|
0
|
|
===DONE===
|