<?
/*
큐(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();
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7530 | 10년 전 | 753 | ||
| 7529 |
파랑새1597
|
10년 전 | 1191 | |
| 7528 |
파랑새1597
|
10년 전 | 1288 | |
| 7527 |
integrity7
|
10년 전 | 1371 | |
| 7526 | 10년 전 | 2396 | ||
| 7525 |
다빈치코드777
|
10년 전 | 1087 | |
| 7524 | 10년 전 | 1550 | ||
| 7523 | 10년 전 | 953 | ||
| 7522 |
|
10년 전 | 974 | |
| 7521 |
blackkil
|
10년 전 | 1849 | |
| 7520 | 10년 전 | 1269 | ||
| 7519 |
Gaumi
|
10년 전 | 1069 | |
| 7518 | 10년 전 | 1471 | ||
| 7517 | 10년 전 | 808 | ||
| 7516 | 10년 전 | 1268 | ||
| 7515 | 10년 전 | 1390 | ||
| 7514 |
|
10년 전 | 4479 | |
| 7513 |
멋진남자임
|
10년 전 | 1127 | |
| 7512 |
다빈치코드777
|
10년 전 | 859 | |
| 7511 |
|
10년 전 | 3381 | |
| 7510 | 10년 전 | 1351 | ||
| 7509 | 10년 전 | 1122 | ||
| 7508 | 10년 전 | 704 | ||
| 7507 |
senseme
|
10년 전 | 723 | |
| 7506 |
멋진남자임
|
10년 전 | 1621 | |
| 7505 | 10년 전 | 3979 | ||
| 7504 | 10년 전 | 2135 | ||
| 7503 | 10년 전 | 987 | ||
| 7502 | 10년 전 | 512 | ||
| 7501 | 10년 전 | 1430 | ||
| 7500 | 10년 전 | 1474 | ||
| 7499 | 10년 전 | 3358 | ||
| 7498 | 10년 전 | 1179 | ||
| 7497 |
dethos79
|
10년 전 | 2952 | |
| 7496 | 10년 전 | 2123 | ||
| 7495 | 10년 전 | 828 | ||
| 7494 |
CHAVO
|
10년 전 | 1111 | |
| 7493 | 10년 전 | 2629 | ||
| 7492 | 10년 전 | 1226 | ||
| 7491 | 10년 전 | 1436 | ||
| 7490 | 10년 전 | 2320 | ||
| 7489 | 10년 전 | 2109 | ||
| 7488 |
toptopon
|
10년 전 | 878 | |
| 7487 |
|
10년 전 | 1021 | |
| 7486 | 10년 전 | 3337 | ||
| 7485 | 10년 전 | 1299 | ||
| 7484 | 10년 전 | 1358 | ||
| 7483 | 10년 전 | 1014 | ||
| 7482 | 10년 전 | 642 | ||
| 7481 | 10년 전 | 852 | ||
| 7480 | 10년 전 | 1212 | ||
| 7479 | 10년 전 | 2592 | ||
| 7478 | 10년 전 | 1140 | ||
| 7477 |
멋진남자임
|
10년 전 | 1491 | |
| 7476 |
zeppeto
|
10년 전 | 1132 | |
| 7475 |
200점아빠
|
10년 전 | 906 | |
| 7474 | 10년 전 | 3996 | ||
| 7473 | 10년 전 | 974 | ||
| 7472 |
나르시스1
|
10년 전 | 1220 | |
| 7471 | 10년 전 | 867 | ||
| 7470 | 10년 전 | 1262 | ||
| 7469 |
플라이SINJI
|
10년 전 | 945 | |
| 7468 |
|
10년 전 | 527 | |
| 7467 |
|
10년 전 | 638 | |
| 7466 | 10년 전 | 1101 | ||
| 7465 | 10년 전 | 1167 | ||
| 7464 |
|
10년 전 | 1173 | |
| 7463 | 10년 전 | 1223 | ||
| 7462 |
진짜별사탕
|
10년 전 | 839 | |
| 7461 | 10년 전 | 930 | ||
| 7460 | 10년 전 | 3709 | ||
| 7459 |
멋진남자임
|
10년 전 | 1540 | |
| 7458 |
멋진남자임
|
10년 전 | 475 | |
| 7457 | 10년 전 | 909 | ||
| 7456 | 10년 전 | 748 | ||
| 7455 | 10년 전 | 2131 | ||
| 7454 | 10년 전 | 621 | ||
| 7453 | 10년 전 | 809 | ||
| 7452 |
중국어사이트제작
|
10년 전 | 501 | |
| 7451 | 10년 전 | 895 | ||
| 7450 | 10년 전 | 620 | ||
| 7449 |
울라라라우
|
10년 전 | 930 | |
| 7448 | 10년 전 | 1625 | ||
| 7447 |
멋진남자임
|
10년 전 | 488 | |
| 7446 | 10년 전 | 532 | ||
| 7445 |
네이비칼라
|
10년 전 | 1650 | |
| 7444 |
senseme
|
10년 전 | 1391 | |
| 7443 | 10년 전 | 1325 | ||
| 7442 | 10년 전 | 711 | ||
| 7441 |
멋진남자임
|
10년 전 | 1422 | |
| 7440 | 10년 전 | 881 | ||
| 7439 |
|
10년 전 | 737 | |
| 7438 |
|
10년 전 | 915 | |
| 7437 |
basement
|
10년 전 | 1023 | |
| 7436 |
잘살아보자
|
10년 전 | 1112 | |
| 7435 | 10년 전 | 1062 | ||
| 7434 | 10년 전 | 3781 | ||
| 7433 |
|
10년 전 | 2718 | |
| 7432 |
alexkim
|
10년 전 | 848 | |
| 7431 |
이웃집초보
|
10년 전 | 1296 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기