Wednesday, September 25, 2024
Google search engine
HomeLanguagesPHP DsPriorityQueue allocate() Function

PHP Ds\PriorityQueue allocate() Function

The Ds\PriorityQueue::allocate() Function in PHP is used to allocate memory for a PriorityQueue class instance. This function allocates sufficient memory for a given capacity for an instance of PriorityQueue class.

Syntax:

void public Ds\PriorityQueue::allocate ( int $capacity )

Parameters: This function accepts a single parameter $capacity which is an integral value denoting the number of values for which capacity is needed to be allocated.

Return Value: This method does not returns any value.

Below programs illustrate the Ds\PriorityQueue::allocate() Function in PHP:

Program 1:




<?php 
  
// Declare new PriorityQueue 
$pq = new \Ds\PriorityQueue(); 
  
echo("Allocated Space is: "); 
  
// Use capacity() function 
var_dump($pq->capacity()); 
  
echo("Allocated space is: "); 
  
// Use allocate() function to 
// allocate capacity 
$pq->allocate(50); 
  
// Display the allocated vector 
// capacity 
var_dump($pq->capacity()); 
  
?> 


Output:

Allocated Space is: int(8)
Allocated space is: int(64)

Program 2:




<?php 
  
// Declare new PriorityQueue 
$pq = new \Ds\PriorityQueue(); 
  
echo("Allocated Space is: "); 
  
// Use capacity() function 
var_dump($pq->capacity()); 
  
echo("Allocated space is: "); 
  
// Use allocate() function to 
// allocate capacity 
$pq->allocate(5); 
  
// Display the allocated vector 
// capacity 
var_dump($pq->capacity()); 
  
// Use allocate() function to 
// allocate capacity 
$pq->allocate(120); 
  
// Display the allocated vector 
// capacity 
var_dump($pq->capacity()); 
  
?> 


Output:

Allocated Space is: int(8)
Allocated space is: int(8)
int(128)

Reference: http://php.net/manual/en/ds-priorityqueue.allocate.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

RELATED ARTICLES

Most Popular

Recent Comments