<?
/*
큐(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();
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7730 | 10년 전 | 1285 | ||
| 7729 | 10년 전 | 1098 | ||
| 7728 |
잘살아보자
|
10년 전 | 564 | |
| 7727 |
잘살아보자
|
10년 전 | 462 | |
| 7726 |
잘살아보자
|
10년 전 | 796 | |
| 7725 |
잘살아보자
|
10년 전 | 528 | |
| 7724 |
잘살아보자
|
10년 전 | 433 | |
| 7723 |
잘살아보자
|
10년 전 | 503 | |
| 7722 |
잘살아보자
|
10년 전 | 442 | |
| 7721 |
잘살아보자
|
10년 전 | 479 | |
| 7720 |
잘살아보자
|
10년 전 | 417 | |
| 7719 |
비긴어게인
|
10년 전 | 662 | |
| 7718 |
|
10년 전 | 2503 | |
| 7717 |
잘살아보자
|
10년 전 | 633 | |
| 7716 |
잘살아보자
|
10년 전 | 373 | |
| 7715 |
잘살아보자
|
10년 전 | 409 | |
| 7714 |
잘살아보자
|
10년 전 | 447 | |
| 7713 | 10년 전 | 1753 | ||
| 7712 | 10년 전 | 1684 | ||
| 7711 | 10년 전 | 1070 | ||
| 7710 | 10년 전 | 1355 | ||
| 7709 | 10년 전 | 1487 | ||
| 7708 | 10년 전 | 1439 | ||
| 7707 | 10년 전 | 834 | ||
| 7706 |
별지기천사
|
10년 전 | 549 | |
| 7705 | 10년 전 | 1050 | ||
| 7704 |
ICONdesignstudio
|
10년 전 | 594 | |
| 7703 | 10년 전 | 562 | ||
| 7702 |
|
10년 전 | 688 | |
| 7701 | 10년 전 | 1388 | ||
| 7700 | 10년 전 | 1085 | ||
| 7699 | 10년 전 | 562 | ||
| 7698 | 10년 전 | 1115 | ||
| 7697 | 10년 전 | 5121 | ||
| 7696 | 10년 전 | 617 | ||
| 7695 | 10년 전 | 1655 | ||
| 7694 | 10년 전 | 1020 | ||
| 7693 | 10년 전 | 1519 | ||
| 7692 | 10년 전 | 1255 | ||
| 7691 | 10년 전 | 785 | ||
| 7690 | 10년 전 | 1369 | ||
| 7689 | 10년 전 | 986 | ||
| 7688 | 10년 전 | 577 | ||
| 7687 |
파랑새1597
|
10년 전 | 559 | |
| 7686 | 10년 전 | 804 | ||
| 7685 | 10년 전 | 1328 | ||
| 7684 | 10년 전 | 774 | ||
| 7683 | 10년 전 | 1024 | ||
| 7682 | 10년 전 | 934 | ||
| 7681 | 10년 전 | 625 | ||
| 7680 | 10년 전 | 970 | ||
| 7679 | 10년 전 | 466 | ||
| 7678 | 10년 전 | 698 | ||
| 7677 | 10년 전 | 599 | ||
| 7676 |
|
10년 전 | 921 | |
| 7675 |
|
10년 전 | 1124 | |
| 7674 | 10년 전 | 1030 | ||
| 7673 | 10년 전 | 731 | ||
| 7672 | 10년 전 | 1063 | ||
| 7671 | 10년 전 | 851 | ||
| 7670 | 10년 전 | 615 | ||
| 7669 |
mashmellow
|
10년 전 | 1206 | |
| 7668 | 10년 전 | 688 | ||
| 7667 | 10년 전 | 967 | ||
| 7666 |
senseme
|
10년 전 | 627 | |
| 7665 | 10년 전 | 482 | ||
| 7664 | 10년 전 | 1873 | ||
| 7663 |
mixx애교
|
10년 전 | 959 | |
| 7662 | 10년 전 | 1008 | ||
| 7661 |
hkhkah
|
10년 전 | 763 | |
| 7660 | 10년 전 | 1043 | ||
| 7659 |
커네드커네드
|
10년 전 | 910 | |
| 7658 |
바람돌이팡
|
10년 전 | 640 | |
| 7657 | 10년 전 | 1143 | ||
| 7656 | 10년 전 | 1544 | ||
| 7655 | 10년 전 | 956 | ||
| 7654 |
개발짜증나
|
10년 전 | 842 | |
| 7653 |
네이비칼라
|
10년 전 | 872 | |
| 7652 |
밥먹고합시다
|
10년 전 | 792 | |
| 7651 |
플라이SINJI
|
10년 전 | 1493 | |
| 7650 |
개발짜증나
|
10년 전 | 1388 | |
| 7649 | 10년 전 | 433 | ||
| 7648 |
이미영ㅇㅇ
|
10년 전 | 845 | |
| 7647 | 10년 전 | 414 | ||
| 7646 | 10년 전 | 777 | ||
| 7645 | 10년 전 | 2280 | ||
| 7644 | 10년 전 | 796 | ||
| 7643 |
|
10년 전 | 2847 | |
| 7642 | 10년 전 | 1493 | ||
| 7641 | 10년 전 | 1111 | ||
| 7640 |
개발짜증나
|
10년 전 | 458 | |
| 7639 |
|
10년 전 | 797 | |
| 7638 |
개발짜증나
|
10년 전 | 1102 | |
| 7637 | 10년 전 | 1523 | ||
| 7636 | 10년 전 | 2884 | ||
| 7635 | 10년 전 | 1667 | ||
| 7634 | 10년 전 | 1837 | ||
| 7633 | 10년 전 | 2304 | ||
| 7632 | 10년 전 | 3905 | ||
| 7631 |
|
10년 전 | 1511 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기