링크
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년 전 | 113 | ||
| 8229 | 9년 전 | 107 | ||
| 8228 |
커네드커네드
|
9년 전 | 154 | |
| 8227 | 9년 전 | 187 | ||
| 8226 | 9년 전 | 206 | ||
| 8225 | 9년 전 | 187 | ||
| 8224 | 9년 전 | 181 | ||
| 8223 | 9년 전 | 158 | ||
| 8222 |
|
9년 전 | 237 | |
| 8221 | 9년 전 | 140 | ||
| 8220 | 9년 전 | 170 | ||
| 8219 | 9년 전 | 132 | ||
| 8218 | 9년 전 | 187 | ||
| 8217 |
star3840
|
9년 전 | 156 | |
| 8216 | 9년 전 | 219 | ||
| 8215 | 9년 전 | 171 | ||
| 8214 | 9년 전 | 265 | ||
| 8213 | 9년 전 | 221 | ||
| 8212 | 9년 전 | 138 | ||
| 8211 | 9년 전 | 305 | ||
| 8210 | 9년 전 | 313 | ||
| 8209 | 9년 전 | 380 | ||
| 8208 | 9년 전 | 280 | ||
| 8207 | 9년 전 | 274 | ||
| 8206 |
|
9년 전 | 236 | |
| 8205 | 9년 전 | 219 | ||
| 8204 | 9년 전 | 190 | ||
| 8203 | 9년 전 | 270 | ||
| 8202 | 9년 전 | 187 | ||
| 8201 | 9년 전 | 228 | ||
| 8200 | 9년 전 | 226 | ||
| 8199 | 9년 전 | 252 | ||
| 8198 | 9년 전 | 218 | ||
| 8197 | 9년 전 | 210 | ||
| 8196 | 9년 전 | 601 | ||
| 8195 | 9년 전 | 210 | ||
| 8194 | 9년 전 | 327 | ||
| 8193 | 9년 전 | 215 | ||
| 8192 | 9년 전 | 248 | ||
| 8191 | 9년 전 | 195 | ||
| 8190 | 9년 전 | 194 | ||
| 8189 | 9년 전 | 246 | ||
| 8188 | 9년 전 | 186 | ||
| 8187 | 9년 전 | 189 | ||
| 8186 | 9년 전 | 193 | ||
| 8185 | 9년 전 | 365 | ||
| 8184 | 9년 전 | 147 | ||
| 8183 | 9년 전 | 368 | ||
| 8182 | 9년 전 | 218 | ||
| 8181 | 9년 전 | 181 | ||
| 8180 | 9년 전 | 755 | ||
| 8179 | 9년 전 | 528 | ||
| 8178 | 9년 전 | 376 | ||
| 8177 |
kiplayer
|
9년 전 | 383 | |
| 8176 | 9년 전 | 411 | ||
| 8175 | 9년 전 | 284 | ||
| 8174 | 9년 전 | 292 | ||
| 8173 | 9년 전 | 382 | ||
| 8172 | 9년 전 | 249 | ||
| 8171 | 9년 전 | 227 | ||
| 8170 | 9년 전 | 341 | ||
| 8169 |
커네드커네드
|
9년 전 | 302 | |
| 8168 | 9년 전 | 369 | ||
| 8167 | 9년 전 | 369 | ||
| 8166 | 9년 전 | 278 | ||
| 8165 | 9년 전 | 216 | ||
| 8164 | 9년 전 | 356 | ||
| 8163 | 9년 전 | 341 | ||
| 8162 | 9년 전 | 351 | ||
| 8161 | 9년 전 | 364 | ||
| 8160 |
|
9년 전 | 554 | |
| 8159 | 9년 전 | 492 | ||
| 8158 | 9년 전 | 304 | ||
| 8157 | 9년 전 | 425 | ||
| 8156 | 9년 전 | 305 | ||
| 8155 | 9년 전 | 299 | ||
| 8154 |
00년생용띠
|
9년 전 | 642 | |
| 8153 | 9년 전 | 282 | ||
| 8152 |
|
9년 전 | 460 | |
| 8151 | 9년 전 | 456 | ||
| 8150 | 9년 전 | 563 | ||
| 8149 |
Jangfolk
|
9년 전 | 409 | |
| 8148 | 9년 전 | 228 | ||
| 8147 | 9년 전 | 428 | ||
| 8146 | 9년 전 | 501 | ||
| 8145 | 9년 전 | 450 | ||
| 8144 | 9년 전 | 416 | ||
| 8143 | 9년 전 | 249 | ||
| 8142 | 9년 전 | 476 | ||
| 8141 | 9년 전 | 424 | ||
| 8140 | 9년 전 | 973 | ||
| 8139 | 9년 전 | 324 | ||
| 8138 |
전갈자리남자
|
9년 전 | 431 | |
| 8137 | 9년 전 | 462 | ||
| 8136 | 9년 전 | 798 | ||
| 8135 |
|
9년 전 | 833 | |
| 8134 |
PlayPixel
|
9년 전 | 569 | |
| 8133 |
|
9년 전 | 489 | |
| 8132 | 9년 전 | 504 | ||
| 8131 | 9년 전 | 871 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기