<?php
function insertion($list)
{
  //start from 1, because the first element is sorted list
  for ($i = 1; $i < count($list); $i++)
    for ($k = 0; $k < $i; $k++)
    {
      $temp = $list[$k];
      if ($list[$i] < $list[$k])
      {
        $list[$k] = $list[$i];
        $list[$i] = $temp;
      }
    }
  return $list;
}
?>
Published in: PHP
Download

Related snippets