"PHP 삽입정렬 구현"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
2번째 줄: 2번째 줄:
;PHP 삽입정렬 구현
;PHP 삽입정렬 구현


<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
function insertion_sort(&$a) {
function insertion_sort(&$a) {
19번째 줄: 19번째 줄:
echo implode(',',$arr);
echo implode(',',$arr);
# -1,0,1,1,4,9,10,22,22,100
# -1,0,1,1,4,9,10,22,22,100
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:57 기준 최신판

1 개요[ | ]

PHP 삽입정렬 구현
<?php
function insertion_sort(&$a) {
    $size = count($a);
    for($i=1; $i<$size; $i++) {
        $temp = $a[$i];
        for($j=$i-1; $j>=0; $j--) {
            if($a[$j]<$temp) break;
            $a[$j+1] = $a[$j];
        }
        $a[$j+1] = $temp;
    }
}
$arr = [9,1,22,4,0,-1,1,22,100,10];
insertion_sort( $arr );
echo implode(',',$arr);
# -1,0,1,1,4,9,10,22,22,100

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}