Ds\Deque::rotate
Ds\Deque::rotate
(PECL ds >= 1.0.0)
Ds \ Deque :: rotate - 通过给定的旋转次数旋转deque。
Description
public void Ds\Deque::rotate ( int $rotations )
按照给定的旋转次数旋转齿轮,这相当于$deque->push($deque->shift())如果旋转次数为正数或$deque->unshift($deque->pop())负数,则连续调用。
参数
rotations
应该旋转deque的次数。
返回值
没有返回值。当前实例的双端队列将被旋转。
例子
示例 #1 Ds\Deque::rotate() example
<?php
$deque = new \Ds\Deque(["a", "b", "c", "d"]
$deque->rotate(1 // "a" is shifted, then pushed.
print_r($deque
$deque->rotate(2 // "b" and "c" are both shifted, the pushed.
print_r($deque
?>
上面的例子会输出类似于:
(
[0] => b
[1] => c
[2] => d
[3] => a
)
Ds\Deque Object
(
[0] => d
[1] => a
[2] => b
[3] => c
)
← Ds\Deque::reversed
Ds\Deque::set →