<?
/*
큐(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();
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 644 | ||
| 7629 |
|
10년 전 | 2370 | |
| 7628 | 10년 전 | 781 | ||
| 7627 |
|
10년 전 | 1013 | |
| 7626 |
|
10년 전 | 1774 | |
| 7625 | 10년 전 | 685 | ||
| 7624 | 10년 전 | 701 | ||
| 7623 |
|
10년 전 | 3055 | |
| 7622 | 10년 전 | 712 | ||
| 7621 |
leeleeleelee
|
10년 전 | 576 | |
| 7620 | 10년 전 | 534 | ||
| 7619 | 10년 전 | 474 | ||
| 7618 | 10년 전 | 1006 | ||
| 7617 | 10년 전 | 718 | ||
| 7616 | 10년 전 | 624 | ||
| 7615 | 10년 전 | 720 | ||
| 7614 | 10년 전 | 1243 | ||
| 7613 |
|
10년 전 | 2073 | |
| 7612 | 10년 전 | 1129 | ||
| 7611 | 10년 전 | 1394 | ||
| 7610 |
|
10년 전 | 1893 | |
| 7609 |
|
10년 전 | 1319 | |
| 7608 |
mwdkim
|
10년 전 | 1112 | |
| 7607 |
|
10년 전 | 1041 | |
| 7606 |
mwdkim
|
10년 전 | 3909 | |
| 7605 | 10년 전 | 680 | ||
| 7604 | 10년 전 | 1018 | ||
| 7603 | 10년 전 | 1638 | ||
| 7602 |
|
10년 전 | 1056 | |
| 7601 |
AniNest
|
10년 전 | 2775 | |
| 7600 |
port443
|
10년 전 | 1013 | |
| 7599 | 10년 전 | 939 | ||
| 7598 | 10년 전 | 1006 | ||
| 7597 | 10년 전 | 4564 | ||
| 7596 |
SeungYeon
|
10년 전 | 882 | |
| 7595 |
untitled
|
10년 전 | 2407 | |
| 7594 |
프로그래머7
|
10년 전 | 1716 | |
| 7593 |
untitled
|
10년 전 | 2351 | |
| 7592 |
untitled
|
10년 전 | 1927 | |
| 7591 |
untitled
|
10년 전 | 2669 | |
| 7590 |
아리마2001
|
10년 전 | 844 | |
| 7589 | 10년 전 | 1096 | ||
| 7588 |
|
10년 전 | 2907 | |
| 7587 | 10년 전 | 1298 | ||
| 7586 | 10년 전 | 659 | ||
| 7585 | 10년 전 | 1674 | ||
| 7584 | 10년 전 | 1403 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1153 | |
| 7582 |
|
10년 전 | 1092 | |
| 7581 | 10년 전 | 1310 | ||
| 7580 | 10년 전 | 974 | ||
| 7579 |
|
10년 전 | 598 | |
| 7578 | 10년 전 | 1417 | ||
| 7577 |
|
10년 전 | 1865 | |
| 7576 | 10년 전 | 1379 | ||
| 7575 |
멋진남자임
|
10년 전 | 1456 | |
| 7574 | 10년 전 | 2103 | ||
| 7573 | 10년 전 | 3238 | ||
| 7572 | 10년 전 | 754 | ||
| 7571 |
|
10년 전 | 775 | |
| 7570 |
|
10년 전 | 1301 | |
| 7569 | 10년 전 | 1534 | ||
| 7568 |
this1mg
|
10년 전 | 1037 | |
| 7567 |
|
10년 전 | 751 | |
| 7566 | 10년 전 | 913 | ||
| 7565 |
Angel하늘
|
10년 전 | 982 | |
| 7564 |
seoldi
|
10년 전 | 1220 | |
| 7563 |
|
10년 전 | 1361 | |
| 7562 |
멋진남자임
|
10년 전 | 2068 | |
| 7561 | 10년 전 | 697 | ||
| 7560 |
leeleeleelee
|
10년 전 | 889 | |
| 7559 | 10년 전 | 5028 | ||
| 7558 |
RinaP
|
10년 전 | 766 | |
| 7557 |
|
10년 전 | 1228 | |
| 7556 | 10년 전 | 1183 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1650 | |
| 7554 | 10년 전 | 1086 | ||
| 7553 |
senseme
|
10년 전 | 1328 | |
| 7552 |
ehdltdoit
|
10년 전 | 1425 | |
| 7551 |
|
10년 전 | 1812 | |
| 7550 |
leeleeleelee
|
10년 전 | 1576 | |
| 7549 | 10년 전 | 2412 | ||
| 7548 | 10년 전 | 1830 | ||
| 7547 |
멋진남자임
|
10년 전 | 1951 | |
| 7546 | 10년 전 | 994 | ||
| 7545 |
ILMare1003
|
10년 전 | 1272 | |
| 7544 |
|
10년 전 | 1233 | |
| 7543 | 10년 전 | 878 | ||
| 7542 | 10년 전 | 649 | ||
| 7541 |
울라라라우
|
10년 전 | 857 | |
| 7540 | 10년 전 | 1593 | ||
| 7539 | 10년 전 | 918 | ||
| 7538 |
|
10년 전 | 1824 | |
| 7537 | 10년 전 | 3600 | ||
| 7536 |
Gaumi
|
10년 전 | 1398 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1255 | |
| 7534 |
senseme
|
10년 전 | 1197 | |
| 7533 | 10년 전 | 1182 | ||
| 7532 | 10년 전 | 848 | ||
| 7531 | 10년 전 | 2037 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기