downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SplMaxHeap::compare> <SplHeap::valid
[edit] Last updated: Fri, 10 Feb 2012

view this page in

The SplMaxHeap class

(PHP 5 >= 5.3.0)

Introdução

The SplMaxHeap class provides the main functionalities of a heap, keeping the maximum on the top.

Sinopse da classe

SplMaxHeap extends SplHeap implements Iterator , Countable {
/* Métodos */
int compare ( mixed $value1 , mixed $value2 )
/* Métodos herdados */
abstract int SplHeap::compare ( mixed $value1 , mixed $value2 )
int SplHeap::count ( void )
mixed SplHeap::current ( void )
mixed SplHeap::extract ( void )
void SplHeap::insert ( mixed $value )
bool SplHeap::isEmpty ( void )
mixed SplHeap::key ( void )
void SplHeap::next ( void )
void SplHeap::rewind ( void )
mixed SplHeap::top ( void )
bool SplHeap::valid ( void )
}

Índice

  • SplMaxHeap::compare — Compare elements in order to place them correctly in the heap while sifting up.


add a note add a note User Contributed Notes SplMaxHeap
MuLoT [ojousset49 at yahoo dot fr] 17-Dec-2010 05:50
SplMaxHeap simple example with integer values...

<?php
class MySimpleHeap extends SplMaxHeap
{
    public function 
compare( $value1, $value2 ) {
        return (
$value1 - $value2 );
    }
}

$obj = new MySimpleHeap();
$obj->insert( 4 );
$obj->insert( 8 );
$obj->insert( 1 );
$obj->insert( 0 );

foreach(
$obj as $number ) {
    echo
$number."\n";
}

/*
    Output display :
    8
    4
    1
    0
*/
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites