"PHP 계수정렬 구현"의 두 판 사이의 차이

잔글 (봇: 카운팅정렬을(를) 계수정렬(으)로 분류 대체함)
25번째 줄: 25번째 줄:
* [[PHP 기수정렬 구현]]
* [[PHP 기수정렬 구현]]


[[분류: PHP 정렬]]
[[분류:PHP 정렬]]
[[분류: 카운팅정렬]]
[[분류:계수정렬]]

2018년 8월 27일 (월) 01:56 판

1 개요

PHP 카운팅정렬 구현
<?php
function counting_sort(&$a) {
    $min = min($a);
    $max = max($a);
    $count = [];
    for($i=$min; $i<=$max; $i++) $count[$i]=0;
    foreach($a as $x) $count[$x]++;
    for($i=$min, $j=0; $i<=$max; $i++) {
        while( $count[$i]-- > 0 ) $a[$j++] = $i;
    }
}
$arr = [9,1,22,4,0,-1,1,22,100,10];
counting_sort( $arr );
echo implode(' ', $arr);
# -1 0 1 1 4 9 10 22 22 100

2 같이 보기

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