Moves the element at index i of list to index (i + distance) mod size, in place; a negative distance rotates left. Any safe integer is accepted. Elements are written with set, so open iterators and cursors stay valid.
i
list
(i + distance)
size
set
Time: O(n).
The list to rotate.
How far to move each element to the right.
TypeError when list is not a list from this library or distance is not a number.
distance
IllegalArgumentError when distance is NaN, infinite, fractional or not a safe integer.
NaN
const list = new ArrayList([1, 2, 3, 4])rotate(list, 1) // list is now [4, 1, 2, 3] Copy
const list = new ArrayList([1, 2, 3, 4])rotate(list, 1) // list is now [4, 1, 2, 3]
Moves the element at index
ioflistto index(i + distance)modsize, in place; a negative distance rotates left. Any safe integer is accepted. Elements are written withset, so open iterators and cursors stay valid.Time: O(n).