The SplHeap::count() function is an inbuilt function in PHP which is used to count the elements in the heap.
Generally, Heap can be 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.
Note: This article uses Max Heap which extends the SplHeap class.
Syntax:
int SplMaxHeap::count()
Parameters: This function does not accept any parameter.
Return Value: This function returns the number of nodes present in heap.
Below programs illustrate the SplMaxHeap::count() function in PHP:
Program 1:
<?php
$heap = new SplMaxHeap();
$heap ->insert( 'GEEKS' );
$heap ->insert( 'gfg' );
echo $heap -> count ();
?>
|
Program 2:
<?php
$heap = new SplMaxHeap();
echo $heap -> count () . "\n" ;
$heap ->insert( 'GEEKS' );
$heap ->insert( 'gfg' );
$heap ->insert( 'DSA' );
$heap ->insert( 'ALGO' );
$heap ->insert( 'C' );
echo $heap -> count ();
?>
|
Reference: https://www.php.net/manual/en/splheap.count.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 :
28 Jun, 2019
Like Article
Save Article