Exchanges the elements at i and j of list; nothing is written when i === j.
i
j
list
i === j
Time: O(1) plus two get and two set calls.
get
set
The list.
One index.
The other index.
TypeError when list is not a list from this library.
IndexOutOfBoundsError when either index is out of bounds; the list is unchanged.
const list = new ArrayList(['a', 'b', 'c'])swap(list, 0, 2) // list is now ['c', 'b', 'a'] Copy
const list = new ArrayList(['a', 'b', 'c'])swap(list, 0, 2) // list is now ['c', 'b', 'a']
Exchanges the elements at
iandjoflist; nothing is written wheni === j.Time: O(1) plus two
getand twosetcalls.