<?
/*
큐(queue)는 컴퓨터의 기본적인 자료 구조의 한가지로,
먼저 집어 넣은 데이터가 먼저 나오는 FIFO (First In First Out)구조로 저장하는 형식을 말한다
http://terms.naver.com/entry.nhn?docId=834442&cid=42344&categoryId=42344
http://ko.wikipedia.org/wiki/%ED%81%90_(%EC%9E%90%EB%A3%8C_%EA%B5%AC%EC%A1%B0)
*/
// 시작노드와 끝노드만 남기고 나머지 노드 삭제
function clear_queue() {
global $head, $tail;
$t = new dnode;
$s = new dnode;
$t = $head->next;
while ($t != $tail) {
$s = $t;
$t = $t->next;
$s = null;
}
$head->next = $tail;
$tail->prev = $head;
}
// 마지막 노드 앞에 새 노드 삽입
function put($k) {
global $head, $tail;
$t = new dnode;
$t->key = $k;
$tail->prev->next = $t;
$t->prev = $tail->prev;
$tail->prev = $t;
$t->next = $tail;
return $k;
}
// 큐에 시작노드 다음 노드의 key 값 가져오기
function get() {
global $head, $tail;
$t = new dnode;
$i = 0;
$t = $head->next;
if ($t == $tail) {
printf('<br /> Queue underflow.');
return -1;
}
$i = $t->key;
$head->next = $t->next;
$t->next->prev = $head;
$t = null;
return $i;
}
// 큐에 저장된 key 값 보여주기
function print_queue() {
global $head, $tail;
$t = $head->next;
printf('<br /> Queue contents : Front ----> Rear<br />');
while ($t != $tail) {
printf('%2d', $t->key);
$t = $t->next;
}
}
// 노드정의
class dnode {
public $key = 0,
$prev = null,
$next = null;
}
$head = new dnode; // 시작노드
$tail = new dnode; // 끝노드
$head->prev = $head;
$head->next = $tail;
$tail->prev = $head;
$tail->next = $tail;
printf('<br />Put 1, 2, 3, 4, 5, 6');
put(1);
put(2);
put(3);
put(4);
put(5);
put(6);
print_queue();
echo ('<br /><br />Get');
$i = get();
printf('<br /> getting value is %d', $i);
print_queue();
printf('<br /><br />Put 7, 8, 9, 1');
put(7);
put(8);
put(9);
put(1);
print_queue();
printf('<br /><br />Put 2');
put(2);
print_queue();
printf('<br /><br />Initialize queue');
clear_queue();
print_queue();
printf('<br /><br />Now queue is empty');
echo ('<br />Get');
$i = get();
printf('<br /> getting value is %d', $i);
print_queue();
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6330 |
|
12년 전 | 1801 | |
| 6329 |
내가짱니네가짱
|
12년 전 | 1226 | |
| 6328 |
AMDbest
|
12년 전 | 492 | |
| 6327 | 12년 전 | 1705 | ||
| 6326 | 12년 전 | 1335 | ||
| 6325 | 12년 전 | 7623 | ||
| 6324 |
AMDbest
|
12년 전 | 2205 | |
| 6323 |
|
12년 전 | 1977 | |
| 6322 | 12년 전 | 2037 | ||
| 6321 | 12년 전 | 2486 | ||
| 6320 |
senseme
|
12년 전 | 591 | |
| 6319 | 12년 전 | 3735 | ||
| 6318 | 12년 전 | 1382 | ||
| 6317 |
kiplayer
|
12년 전 | 6418 | |
| 6316 | 12년 전 | 1017 | ||
| 6315 | 12년 전 | 975 | ||
| 6314 |
상엽나르도
|
12년 전 | 1286 | |
| 6313 |
검은고양이1983
|
12년 전 | 654 | |
| 6312 | 12년 전 | 3116 | ||
| 6311 | 12년 전 | 1414 | ||
| 6310 |
testers
|
12년 전 | 1483 | |
| 6309 | 12년 전 | 988 | ||
| 6308 | 12년 전 | 2602 | ||
| 6307 | 12년 전 | 1655 | ||
| 6306 | 12년 전 | 438 | ||
| 6305 | 12년 전 | 3500 | ||
| 6304 | 12년 전 | 998 | ||
| 6303 | 12년 전 | 823 | ||
| 6302 | 12년 전 | 1190 | ||
| 6301 | 12년 전 | 5570 | ||
| 6300 |
|
12년 전 | 1197 | |
| 6299 |
AMDbest
|
12년 전 | 2805 | |
| 6298 |
AMDbest
|
12년 전 | 2250 | |
| 6297 |
프리랜서개발자
|
12년 전 | 476 | |
| 6296 | 12년 전 | 2932 | ||
| 6295 |
SUPERMANs
|
12년 전 | 1386 | |
| 6294 | 12년 전 | 1293 | ||
| 6293 | 12년 전 | 1345 | ||
| 6292 |
오늘도망했다
|
12년 전 | 3270 | |
| 6291 |
senseme
|
12년 전 | 2032 | |
| 6290 |
senseme
|
12년 전 | 3688 | |
| 6289 |
senseme
|
12년 전 | 8580 | |
| 6288 |
senseme
|
12년 전 | 4173 | |
| 6287 |
senseme
|
12년 전 | 3745 | |
| 6286 |
senseme
|
12년 전 | 1365 | |
| 6285 |
senseme
|
12년 전 | 1438 | |
| 6284 |
프로프리랜서
|
12년 전 | 3160 | |
| 6283 |
프로프리랜서
|
12년 전 | 3991 | |
| 6282 |
프로프리랜서
|
12년 전 | 4395 | |
| 6281 |
프로프리랜서
|
12년 전 | 1605 | |
| 6280 | 12년 전 | 1290 | ||
| 6279 |
AMDbest
|
12년 전 | 880 | |
| 6278 | 12년 전 | 981 | ||
| 6277 |
senseme
|
12년 전 | 2719 | |
| 6276 |
senseme
|
12년 전 | 2735 | |
| 6275 |
senseme
|
12년 전 | 1261 | |
| 6274 |
|
12년 전 | 2806 | |
| 6273 | 12년 전 | 1279 | ||
| 6272 | 12년 전 | 8462 | ||
| 6271 |
senseme
|
12년 전 | 1512 | |
| 6270 |
senseme
|
12년 전 | 3772 | |
| 6269 |
senseme
|
12년 전 | 6380 | |
| 6268 |
senseme
|
12년 전 | 1565 | |
| 6267 | 12년 전 | 2843 | ||
| 6266 | 12년 전 | 580 | ||
| 6265 | 12년 전 | 1302 | ||
| 6264 | 12년 전 | 1157 | ||
| 6263 |
senseme
|
12년 전 | 1318 | |
| 6262 |
senseme
|
12년 전 | 3314 | |
| 6261 |
senseme
|
12년 전 | 1089 | |
| 6260 |
senseme
|
12년 전 | 1830 | |
| 6259 |
senseme
|
12년 전 | 1260 | |
| 6258 |
senseme
|
12년 전 | 919 | |
| 6257 | 12년 전 | 1407 | ||
| 6256 | 12년 전 | 2101 | ||
| 6255 |
senseme
|
12년 전 | 1381 | |
| 6254 |
senseme
|
12년 전 | 1267 | |
| 6253 |
senseme
|
12년 전 | 1789 | |
| 6252 |
kiplayer
|
12년 전 | 14778 | |
| 6251 | 12년 전 | 1073 | ||
| 6250 | 12년 전 | 870 | ||
| 6249 | 12년 전 | 2728 | ||
| 6248 |
senseme
|
12년 전 | 8965 | |
| 6247 | 12년 전 | 1291 | ||
| 6246 |
프로프리랜서
|
12년 전 | 1170 | |
| 6245 |
프로프리랜서
|
12년 전 | 1628 | |
| 6244 |
프로프리랜서
|
12년 전 | 1130 | |
| 6243 |
프로프리랜서
|
12년 전 | 1261 | |
| 6242 |
프로프리랜서
|
12년 전 | 3551 | |
| 6241 |
프로프리랜서
|
12년 전 | 1457 | |
| 6240 |
프로프리랜서
|
12년 전 | 2126 | |
| 6239 |
softhead
|
12년 전 | 1142 | |
| 6238 |
senseme
|
12년 전 | 1311 | |
| 6237 |
senseme
|
12년 전 | 3028 | |
| 6236 | 12년 전 | 876 | ||
| 6235 | 12년 전 | 1343 | ||
| 6234 | 12년 전 | 1605 | ||
| 6233 | 12년 전 | 2034 | ||
| 6232 | 12년 전 | 2139 | ||
| 6231 | 12년 전 | 2566 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기