I got the following task, and unfortunately I have no idea how to solve it.
You have the following function already implemented:
function array_swap(&$ar,$j) { ... } // changes element at position $j with element at position 0
/*
* Example:
* $ar=array(3,1,5);
* array_swap($ar, 2); // change element at position 2 with element at position 0
* result is array(5,1,3);
*/
1 You must use array_swap function
2 You can compare elements in the array
3 You can use any loops (for, foreach, while, etc)
4 The task is to sort the array ascending
Can someone give me help, ideas how to implement this? Maybe an algorithm enough, I hope so I can code. :) This is an algorithm question, and I checked the existing algorithms before, but didn't found any similar.