In the circular queue, we can use an empty data cell again when we remove the cell value using a dequeue. Another important thing is we can not add value before the end of the head index( for example, if my array size is 5 and the head point to an index of 0, then we need to empty the array index 4. Which means we can add 4 value when the array size is 5). We can use this queue implementation in banking software( ex: give tokens to customers and call them according to that token). Here is the complete code below:
$devisor = 5;
$data_array = [];
$head = 0;
$tail = 0;
function enqueue( $item = NULL ){
global $head, $tail, $data_array, $devisor;
if(empty($item)){
echo 'invalid function call. Need to pass item as a function parametter';
return;
}
$tail = $tail % $devisor;
$next_tindex = $tail + 1;
if( $head == $next_tindex % $devisor){
echo 'Queue is full';
return;
}else{
$data_array[$tail] = $item;
$tail++;
}
return $data_array;
}
function dequeue(){
global $head,$tail,$devisor,$data_array;
if($tail == $head){
echo 'Queue is empty';
return -1;
}
$item = $data_array[$head];
$head = ++$head % $devisor;
return $item;
}
echo '<pre>';
print_r(enqueue(1));
echo '</pre>';
echo '<pre>';
print_r(dequeue());
echo '</pre>';
Plugins to Enhance Your WooCommerce Store
Carefully selected tools to help you customize, manage, and optimize your WooCommerce experience.
Woo Parent Category Selector
- Automatically assign parent categories when child categories are selected
- Prevent accidental removal of required parent categories
- Automatically repairs missing parent category assignments during product save
- Bulk repair existing WooCommerce product category structures
- Keeps product category structures organized and consistent
Product Catalog Mode For WooCommerce
- Turn your WooCommerce store into catalog mode instantly
- Hide Add to Cart buttons and product prices conditionally
- Apply rules by user role, country, or scheduled time periods
- Display custom messages and inquiry options for products
- Control visibility settings globally or per product
Remove Add to Cart Button for WooCommerce
- Remove Add to Cart buttons from shop and product pages
- Hide buttons conditionally for selected products or categories
- Replace Add to Cart with custom text or messages
- Control button visibility by user role and product type
- Lightweight settings interface with easy customization
Remove Product Content for WooCommerce
- Hide product title, image, price, rating, and descriptions
- Remove tabs, meta information, SKU, tags, and related products
- Control visibility separately for shop and single product pages
- Customize WooCommerce layouts without coding
- Enable or disable content elements with simple settings
Really Simple XML and HTML Sitemap
- Generate both XML and HTML sitemaps automatically
- Display sitemaps anywhere using ShortCode support
- Include pages, posts, and custom post types
- Exclude selected pages or posts easily
- Supports WPML and Polylang multilingual plugins
