자료구조 Ds\Sequence::rotate

(PECL ds >= 1.0.0)

Ds\Sequence::rotate — 주어진 회전 수만큼 시퀀스를 회전합니다.


설명

abstract public Ds\Sequence::rotate(int $rotations): void

주어진 회전 수만큼 시퀀스를 회전합니다. 이는 회전 수가 양수인 경우 $sequence->push($sequence->shift())를 연속적으로 호출하는 것과 동일하거나 $sequence->unshift($sequence->pop()) 음수인 경우.


매개변수

rotations
시퀀스를 회전해야 하는 횟수입니다.

반환 값

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


Examples

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

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

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

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

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

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