Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
Simple9371 (talk | contribs) m (Minor edit...) |
Simple9371 (talk | contribs) (Added P) |
||
Line 1,839: | Line 1,839: | ||
END INSSORT; |
END INSSORT; |
||
</lang> |
</lang> |
||
=={{header|PowerShell}}== |
|||
Very similar to the PHP code. |
|||
<lang powershell>function insertionSort($arr){ |
|||
for($i=0;$i -lt $arr.length;$i++){ |
|||
$val = $arr[$i] |
|||
$j = $i-1 |
|||
while($j -ge 0 -and $arr[$j] -gt $val){ |
|||
$arr[$j+1] = $arr[$j] |
|||
$j-- |
|||
} |
|||
$arr[$j+1] = $val |
|||
} |
|||
} |
|||
$arr = @(4,2,1,6,9,3,8,7) |
|||
insertionSort($arr) |
|||
$arr -join ","</lang> |
|||
{{Out}} |
|||
<pre>1,2,3,4,6,7,8,9</pre> |
|||
=={{header|Prolog}}== |
=={{header|Prolog}}== |