Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. <?php
  2. function insertionSort() {
  3. $ary = [5, 2, 4, 6, 1, 3];
  4. for($j = 1; $j < count($ary); $j++) {
  5. $key = $ary[$j];
  6. $i = $j-1;
  7. while($i >= 0 && $ary[$i] > $key) {
  8. $ary[$i+1] = $ary[$i];
  9. $i = $i-1;
  10. $ary[$i+1] = $key;
  11. }
  12. }
  13. }
  14. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement