I have an array like this:
$a = [2, 1, 1, 2, 3, 1, 3, 2];
I need to sort it, by using an external variable. But I need the following output:
$output = [
[0, s], // Move $a[0] to storage
[5, 0], // Move $a[5] to $[0]
[s, 5], // Move storage to $a[5]
[4, s], // Move $a[4] to storage
[7, 4], // Move $a[7] to $a[4]
[s, 7] // Move storage to $[7]
];
I need an algorithm to make an array, a delimitered string, or any kind of output, containing the steps to sort the array.
Mainly in PHP but I can implement it from any lang.