<?php
//64160267 Kanokpol Promtha
// Insertion Sort
function exam04($arry){
$count = 0;
for($i = 0; $i < count($arry); $i++) {
$tmp = $arry[$i];
$j = $i - 1;
while($j >= 0 && $arry[$j] > $tmp) {
$arry[$j + 1] = $arry[$j];
$j = $j - 1;
// count sum
$count++;
}
$arry[$j + 1] = $tmp;
}
return $count;
}
function test_01(){
if(exam04([2, 1, 3, 1, 2]) == 4){
echo "pass";
} else {
echo "fail";
}
}
test_01();