링크
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년 전 | 65 | ||
| 8229 | 9년 전 | 65 | ||
| 8228 |
커네드커네드
|
9년 전 | 109 | |
| 8227 | 9년 전 | 119 | ||
| 8226 | 9년 전 | 157 | ||
| 8225 | 9년 전 | 144 | ||
| 8224 | 9년 전 | 143 | ||
| 8223 | 9년 전 | 111 | ||
| 8222 |
|
9년 전 | 178 | |
| 8221 | 9년 전 | 83 | ||
| 8220 | 9년 전 | 95 | ||
| 8219 | 9년 전 | 95 | ||
| 8218 | 9년 전 | 130 | ||
| 8217 |
star3840
|
9년 전 | 107 | |
| 8216 | 9년 전 | 157 | ||
| 8215 | 9년 전 | 103 | ||
| 8214 | 9년 전 | 220 | ||
| 8213 | 9년 전 | 152 | ||
| 8212 | 9년 전 | 78 | ||
| 8211 | 9년 전 | 238 | ||
| 8210 | 9년 전 | 238 | ||
| 8209 | 9년 전 | 330 | ||
| 8208 | 9년 전 | 210 | ||
| 8207 | 9년 전 | 220 | ||
| 8206 |
|
9년 전 | 181 | |
| 8205 | 9년 전 | 165 | ||
| 8204 | 9년 전 | 125 | ||
| 8203 | 9년 전 | 225 | ||
| 8202 | 9년 전 | 135 | ||
| 8201 | 9년 전 | 175 | ||
| 8200 | 9년 전 | 151 | ||
| 8199 | 9년 전 | 204 | ||
| 8198 | 9년 전 | 167 | ||
| 8197 | 9년 전 | 157 | ||
| 8196 | 9년 전 | 544 | ||
| 8195 | 9년 전 | 150 | ||
| 8194 | 9년 전 | 277 | ||
| 8193 | 9년 전 | 150 | ||
| 8192 | 9년 전 | 179 | ||
| 8191 | 9년 전 | 132 | ||
| 8190 | 9년 전 | 125 | ||
| 8189 | 9년 전 | 184 | ||
| 8188 | 9년 전 | 125 | ||
| 8187 | 9년 전 | 137 | ||
| 8186 | 9년 전 | 138 | ||
| 8185 | 9년 전 | 303 | ||
| 8184 | 9년 전 | 104 | ||
| 8183 | 9년 전 | 320 | ||
| 8182 | 9년 전 | 162 | ||
| 8181 | 9년 전 | 123 | ||
| 8180 | 9년 전 | 689 | ||
| 8179 | 9년 전 | 480 | ||
| 8178 | 9년 전 | 301 | ||
| 8177 |
kiplayer
|
9년 전 | 306 | |
| 8176 | 9년 전 | 346 | ||
| 8175 | 9년 전 | 213 | ||
| 8174 | 9년 전 | 232 | ||
| 8173 | 9년 전 | 341 | ||
| 8172 | 9년 전 | 188 | ||
| 8171 | 9년 전 | 179 | ||
| 8170 | 9년 전 | 293 | ||
| 8169 |
커네드커네드
|
9년 전 | 252 | |
| 8168 | 9년 전 | 311 | ||
| 8167 | 9년 전 | 313 | ||
| 8166 | 9년 전 | 230 | ||
| 8165 | 9년 전 | 159 | ||
| 8164 | 9년 전 | 298 | ||
| 8163 | 9년 전 | 278 | ||
| 8162 | 9년 전 | 293 | ||
| 8161 | 9년 전 | 286 | ||
| 8160 |
|
9년 전 | 482 | |
| 8159 | 9년 전 | 421 | ||
| 8158 | 9년 전 | 235 | ||
| 8157 | 9년 전 | 368 | ||
| 8156 | 9년 전 | 272 | ||
| 8155 | 9년 전 | 249 | ||
| 8154 |
00년생용띠
|
9년 전 | 595 | |
| 8153 | 9년 전 | 224 | ||
| 8152 |
|
9년 전 | 400 | |
| 8151 | 9년 전 | 402 | ||
| 8150 | 9년 전 | 495 | ||
| 8149 |
Jangfolk
|
9년 전 | 338 | |
| 8148 | 9년 전 | 160 | ||
| 8147 | 9년 전 | 367 | ||
| 8146 | 9년 전 | 426 | ||
| 8145 | 9년 전 | 371 | ||
| 8144 | 9년 전 | 339 | ||
| 8143 | 9년 전 | 187 | ||
| 8142 | 9년 전 | 424 | ||
| 8141 | 9년 전 | 376 | ||
| 8140 | 9년 전 | 921 | ||
| 8139 | 9년 전 | 253 | ||
| 8138 |
전갈자리남자
|
9년 전 | 382 | |
| 8137 | 9년 전 | 388 | ||
| 8136 | 9년 전 | 739 | ||
| 8135 |
|
9년 전 | 788 | |
| 8134 |
PlayPixel
|
9년 전 | 504 | |
| 8133 |
|
9년 전 | 430 | |
| 8132 | 9년 전 | 441 | ||
| 8131 | 9년 전 | 804 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기