자료구조 Ds\Deque::rotate

(PECL ds >= 1.0.0)

Ds\Deque::rotate — 주어진 회전 수만큼 데크를 회전시킵니다.


설명

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

주어진 회전 수만큼 데크를 회전합니다. 이는 회전 수가 양수인 경우 $deque->push($deque->shift())를 연속적으로 호출하거나 $deque->unshift($deque->pop())를 호출하는 것과 같습니다. 음수인 경우.


매개변수

rotations
데크가 회전해야 하는 횟수입니다.

반환 값

값이 반환되지 않습니다. 현재 인스턴스의 데크가 회전됩니다.


Examples

예제 #1 Ds\Deque::rotate() 예제

                  
<?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
)