SplHeap::extract

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

SplHeap::extractExtrait un nœud du haut du tas

Description

public SplHeap::extract(): mixed

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

La valeur du nœud extrait.

Erreurs / Exceptions

Lance une exception RuntimeException lorsque la structure de données est vide.

add a note

User Contributed Notes 1 note

up
11
Sandro Alves Peres
12 years ago
<?php$heap = new SplMaxHeap(); # Ascending order$heap->insert('E');$heap->insert('B');$heap->insert('D');$heap->insert('A');$heap->insert('C');echo $heap->extract(), PHP_EOL; # Eecho $heap->extract(), PHP_EOL; # D$heap = new SplMinHeap(); # Descending order$heap->insert('E');$heap->insert('B');$heap->insert('D');$heap->insert('A');$heap->insert('C');print PHP_EOL;echo $heap->extract(), PHP_EOL; # Aecho $heap->extract(), PHP_EOL; # B?>
To Top