The SplHeap::next() function is an inbuilt function in PHP that is used to move to the next node. This will delete the top node of the heap.
Generally, the Heap Data Structure is of two types.
- Max-Heap: In a Max-Heap the key present at the root node must be greatest among the keys present at all of its children. The same property must be recursively true for all sub-trees in that Binary Tree.
- Min-Heap: In a Min-Heap the key present at the root node must be minimum among the keys present at all of its children. The same property must be recursively true for all sub-trees in that Binary Tree.
Syntax:
void SplHeap::next()
Parameters: This function does not accept any parameter.
Return Value: This function does not return any value.
Below programs illustrate the SplHeap::next() function in PHP:
Example 1:
PHP
<?php
$heap = new SplMinHeap();
$heap ->insert( 'System' . '<br/>' );
$heap ->insert( 'GFG' . '<br/>' );
$heap ->insert( 'ALGO' . '<br/>' );
$heap ->insert( 'C' . '<br/>' );
$heap ->insert( 'Geeks' . '<br/>' );
$heap ->insert( 'GeeksforGeeks' . '<br/>' );
for ( $heap ->top(); $heap ->valid(); $heap ->next()) {
echo $heap ->current() . "\n" ;
}
?>
|
Output:
ALGO
C
GFG
Geeks
GeeksforGeeks
System
Example 2:
PHP
<?php
$heap = new SplMaxHeap();
$heap ->insert( 'System' . '<br/>' );
$heap ->insert( 'GFG' . '<br/>' );
$heap ->insert( 'ALGO' . '<br/>' );
$heap ->insert( 'C' . '<br/>' );
$heap ->insert( 'Geeks' . '<br/>' );
$heap ->insert( 'GeeksforGeeks' . '<br/>' );
for ( $heap ->top(); $heap ->valid(); $heap ->next()) {
echo $heap ->current() . "\n" ;
}
?>
|
Output:
System
GeeksforGeeks
Geeks
GFG
C
ALGO
Reference: https://www.php.net/manual/en/splheap.next.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 Mar, 2021
Like Article
Save Article