• PHP Video Tutorials

PHP - Ds Deque rotate() Function



Ds\Deque::rotate() function can rotate the deque by a given number of rotations.

Syntax

public void Ds\Deque::rotate( int $rotations )

Ds\Deque::rotate() function can rotate the deque by a given number of rotations that is equivalent to successively calling $deque->push($deque->shift()) if the number of rotations is positive, or $deque->unshift($deque->pop()) if negative.

Ds\Deque::rotate() function doesn't return any value, and the deque of the current instance can be rotated.

Example 1

<?php 
   $deque = new \Ds\Deque([1, 2, 3, 4, 5]); 
   echo("The elements in deque: \n"); 
   print_r($deque); 
   
   $deque->rotate(3); 
   echo("The rotated deque: \n"); 
   print_r($deque);
?>

Example 2

<?php 
   $deque = new \Ds\Deque(["Tutorials", "Point", "India", "Tutorix"]); 
   echo("The elements in deque: \n"); 
   print_r($deque); 
   
   $deque->rotate(3); 
   echo("The rotated deque: \n"); 
   print_r($deque); 
?>
php_function_reference.htm
Advertisements