자료구조 Ds\Vector::rotate

(PECL ds >= 1.0.0)

Ds\Vector::rotate — 주어진 회전 수만큼 벡터를 회전합니다.


설명

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

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


매개변수

rotations
벡터를 회전해야 하는 횟수입니다.

반환 값

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


Examples

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

                  
<?php
$vector = new \Ds\Vector(["a", "b", "c", "d"]);

$vector->rotate(1);  // "a" is shifted, then pushed.
print_r($vector);

$vector->rotate(2);  // "b" and "c" are both shifted, the pushed.
print_r($vector);
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

(
    [0] => b
    [1] => c
    [2] => d
    [3] => a
)
Ds\Vector Object
(
    [0] => d
    [1] => a
    [2] => b
    [3] => c
)