링크
http://terms.naver.com/entry.nhn?docId=2270444&cid=51173&categoryId=51173 (15) https://ko.wikipedia.org/wiki/%ED%80%B5_%EC%A0%95%EB%A0%AC (15)<?
// 퀵 정렬(Quick Sort)
function Swap(&$arr, $idx1, $idx2) {
$temp = $arr[$idx1];
$arr[$idx1] = $arr[$idx2];
$arr[$idx2] = $temp;
}
// 중간값 찾기
function MedianOfThree($arr, $left, $right) {
$samples = array($left, floor(($left+$right)/2), $right);
if ($arr[$samples[0]] > $arr[$samples[1]])
Swap($samples, 0, 1);
if ($arr[$samples[1]] > $arr[$samples[2]])
Swap($samples, 1, 2);
if ($arr[$samples[0]] > $arr[$samples[1]])
Swap($samples, 0, 1);
return $samples[1];
}
function Partition(&$arr, $left, $right) {
$pIdx = MedianOfThree($arr, $left, $right); // 중간값으로 피벗 선택
$pivot = $arr[$pIdx];
$low = $left + 1;
$high = $right;
Swap($arr, $left, $pIdx); // 피벗을 가장 왼쪽으로 이동
while ($low <= $high) { // 교차되지 않을 때까지 반복
// 피벗보다 큰 값을 찾는 과정
while ($low <= $right && $pivot >= $arr[$low])
$low++;
// 피벗보다 작은 값을 찾는 과정
while ($high >= ($left+1) && $pivot <= $arr[$high])
$high--;
// 교차되지 않는 상태라면 Swap 실행
if ($low <= $high)
Swap($arr, $low, $high);
}
Swap($arr, $left, $high); // 피벗과 high 가 가리키는 대상 교환
return $high; // 옮겨진 피벗의 위치정보 교환
}
function QuickSort(&$arr, $left, $right) {
if ($left < $right) {
$pivot = Partition($arr, $left, $right);
QuickSort($arr, $left, $pivot-1);
QuickSort($arr, $pivot+1, $right);
}
}
$arr = array(3, 2, 4, 1, 7, 6, 5);
$len = count($arr);
QuickSort($arr, 0, $len-1);
print_r($arr);
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8230 | 9년 전 | 163 | ||
| 8229 | 9년 전 | 135 | ||
| 8228 |
커네드커네드
|
9년 전 | 183 | |
| 8227 | 9년 전 | 227 | ||
| 8226 | 9년 전 | 242 | ||
| 8225 | 9년 전 | 220 | ||
| 8224 | 9년 전 | 229 | ||
| 8223 | 9년 전 | 207 | ||
| 8222 |
|
9년 전 | 266 | |
| 8221 | 9년 전 | 170 | ||
| 8220 | 9년 전 | 208 | ||
| 8219 | 9년 전 | 176 | ||
| 8218 | 9년 전 | 226 | ||
| 8217 |
star3840
|
9년 전 | 195 | |
| 8216 | 9년 전 | 258 | ||
| 8215 | 9년 전 | 204 | ||
| 8214 | 9년 전 | 319 | ||
| 8213 | 9년 전 | 272 | ||
| 8212 | 9년 전 | 177 | ||
| 8211 | 9년 전 | 354 | ||
| 8210 | 9년 전 | 353 | ||
| 8209 | 9년 전 | 429 | ||
| 8208 | 9년 전 | 317 | ||
| 8207 | 9년 전 | 328 | ||
| 8206 |
|
9년 전 | 277 | |
| 8205 | 9년 전 | 250 | ||
| 8204 | 9년 전 | 234 | ||
| 8203 | 9년 전 | 308 | ||
| 8202 | 9년 전 | 227 | ||
| 8201 | 9년 전 | 262 | ||
| 8200 | 9년 전 | 273 | ||
| 8199 | 9년 전 | 296 | ||
| 8198 | 9년 전 | 260 | ||
| 8197 | 9년 전 | 244 | ||
| 8196 | 9년 전 | 663 | ||
| 8195 | 9년 전 | 254 | ||
| 8194 | 9년 전 | 366 | ||
| 8193 | 9년 전 | 273 | ||
| 8192 | 9년 전 | 289 | ||
| 8191 | 9년 전 | 243 | ||
| 8190 | 9년 전 | 226 | ||
| 8189 | 9년 전 | 292 | ||
| 8188 | 9년 전 | 222 | ||
| 8187 | 9년 전 | 231 | ||
| 8186 | 9년 전 | 231 | ||
| 8185 | 9년 전 | 399 | ||
| 8184 | 9년 전 | 185 | ||
| 8183 | 9년 전 | 399 | ||
| 8182 | 9년 전 | 265 | ||
| 8181 | 9년 전 | 226 | ||
| 8180 | 9년 전 | 790 | ||
| 8179 | 9년 전 | 566 | ||
| 8178 | 9년 전 | 430 | ||
| 8177 |
kiplayer
|
9년 전 | 424 | |
| 8176 | 9년 전 | 458 | ||
| 8175 | 9년 전 | 347 | ||
| 8174 | 9년 전 | 336 | ||
| 8173 | 9년 전 | 429 | ||
| 8172 | 9년 전 | 306 | ||
| 8171 | 9년 전 | 270 | ||
| 8170 | 9년 전 | 385 | ||
| 8169 |
커네드커네드
|
9년 전 | 340 | |
| 8168 | 9년 전 | 420 | ||
| 8167 | 9년 전 | 408 | ||
| 8166 | 9년 전 | 313 | ||
| 8165 | 9년 전 | 257 | ||
| 8164 | 9년 전 | 391 | ||
| 8163 | 9년 전 | 391 | ||
| 8162 | 9년 전 | 382 | ||
| 8161 | 9년 전 | 397 | ||
| 8160 |
|
9년 전 | 612 | |
| 8159 | 9년 전 | 556 | ||
| 8158 | 9년 전 | 350 | ||
| 8157 | 9년 전 | 463 | ||
| 8156 | 9년 전 | 345 | ||
| 8155 | 9년 전 | 350 | ||
| 8154 |
00년생용띠
|
9년 전 | 679 | |
| 8153 | 9년 전 | 318 | ||
| 8152 |
|
9년 전 | 497 | |
| 8151 | 9년 전 | 496 | ||
| 8150 | 9년 전 | 605 | ||
| 8149 |
Jangfolk
|
9년 전 | 465 | |
| 8148 | 9년 전 | 281 | ||
| 8147 | 9년 전 | 463 | ||
| 8146 | 9년 전 | 548 | ||
| 8145 | 9년 전 | 500 | ||
| 8144 | 9년 전 | 471 | ||
| 8143 | 9년 전 | 301 | ||
| 8142 | 9년 전 | 512 | ||
| 8141 | 9년 전 | 458 | ||
| 8140 | 9년 전 | 1022 | ||
| 8139 | 9년 전 | 374 | ||
| 8138 |
전갈자리남자
|
9년 전 | 472 | |
| 8137 | 9년 전 | 511 | ||
| 8136 | 9년 전 | 844 | ||
| 8135 |
|
9년 전 | 880 | |
| 8134 |
PlayPixel
|
9년 전 | 619 | |
| 8133 |
|
9년 전 | 529 | |
| 8132 | 9년 전 | 565 | ||
| 8131 | 9년 전 | 923 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기