PHP SplHeap isEmpty() Function
The SplHeap::isEmpty() function is an inbuilt function in PHP which is used to check whether the heap is empty or not.
Generally, the Heap Data Structure are 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:
bool SplHeap::isEmpty()
Parameters: This function does not accept any parameter.
Return Value: This function returns whether the heap is empty.
Below programs illustrate the SplHeap::isEmpty() function in PHP:
Example 1:
PHP
<?php
$heap1 = new SplMaxHeap();
$heap2 = new SplMaxHeap();
$heap2 ->insert( 'System' );
$heap2 ->insert( 'GFG' );
var_dump( $heap1 ->isEmpty());
var_dump( $heap2 ->isEmpty());
?>
|
Output:
bool(true)
bool(false)
Example 2:
PHP
<?php
$heap1 = new SplMinHeap();
$heap2 = new SplMinHeap();
$heap2 ->insert( 'System' );
$heap2 ->insert( 'GFG' );
var_dump( $heap1 ->isEmpty());
var_dump( $heap2 ->isEmpty());
?>
|
Output:
bool(true)
bool(false)
Reference: https://www.php.net/manual/en/splheap.isempty.php
Last Updated :
23 Mar, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...