<?
/*
큐(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();
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6830 |
112211dd
|
11년 전 | 795 | |
| 6829 |
진짜다진짜가나타남
|
11년 전 | 1217 | |
| 6828 | 11년 전 | 827 | ||
| 6827 |
봉보로봉봉
|
11년 전 | 919 | |
| 6826 |
jinion
|
11년 전 | 831 | |
| 6825 | 11년 전 | 808 | ||
| 6824 |
yunkiri486
|
11년 전 | 727 | |
| 6823 |
2donggalbi
|
11년 전 | 856 | |
| 6822 | 11년 전 | 854 | ||
| 6821 | 11년 전 | 803 | ||
| 6820 | 11년 전 | 3109 | ||
| 6819 | 11년 전 | 1258 | ||
| 6818 | 11년 전 | 519 | ||
| 6817 |
|
11년 전 | 617 | |
| 6816 | 11년 전 | 2085 | ||
| 6815 | 11년 전 | 1218 | ||
| 6814 | 11년 전 | 872 | ||
| 6813 | 11년 전 | 618 | ||
| 6812 |
|
11년 전 | 990 | |
| 6811 | 11년 전 | 592 | ||
| 6810 | 11년 전 | 1544 | ||
| 6809 |
낚시가좋아
|
11년 전 | 1050 | |
| 6808 | 11년 전 | 448 | ||
| 6807 | 11년 전 | 779 | ||
| 6806 |
Unhappy
|
11년 전 | 1778 | |
| 6805 | 11년 전 | 1613 | ||
| 6804 | 11년 전 | 1132 | ||
| 6803 | 11년 전 | 579 | ||
| 6802 |
asdfg
|
11년 전 | 1147 | |
| 6801 |
아트귀농인
|
11년 전 | 506 | |
| 6800 | 11년 전 | 2561 | ||
| 6799 | 11년 전 | 1360 | ||
| 6798 | 11년 전 | 1474 | ||
| 6797 | 11년 전 | 632 | ||
| 6796 |
purple63
|
11년 전 | 432 | |
| 6795 | 11년 전 | 2639 | ||
| 6794 |
커네드커네드
|
11년 전 | 963 | |
| 6793 | 11년 전 | 411 | ||
| 6792 | 11년 전 | 2501 | ||
| 6791 | 11년 전 | 532 | ||
| 6790 | 11년 전 | 2264 | ||
| 6789 |
리아빌리티
|
11년 전 | 3102 | |
| 6788 | 11년 전 | 1346 | ||
| 6787 | 11년 전 | 682 | ||
| 6786 | 11년 전 | 392 | ||
| 6785 | 11년 전 | 723 | ||
| 6784 |
|
11년 전 | 853 | |
| 6783 | 11년 전 | 591 | ||
| 6782 | 11년 전 | 3659 | ||
| 6781 |
리아빌리티
|
11년 전 | 494 | |
| 6780 | 11년 전 | 541 | ||
| 6779 | 11년 전 | 491 | ||
| 6778 | 11년 전 | 4704 | ||
| 6777 |
바보온달123
|
11년 전 | 624 | |
| 6776 | 11년 전 | 934 | ||
| 6775 | 11년 전 | 737 | ||
| 6774 |
DANet
|
11년 전 | 644 | |
| 6773 | 11년 전 | 1561 | ||
| 6772 | 11년 전 | 1362 | ||
| 6771 | 11년 전 | 620 | ||
| 6770 | 11년 전 | 1161 | ||
| 6769 | 11년 전 | 960 | ||
| 6768 | 11년 전 | 694 | ||
| 6767 | 11년 전 | 589 | ||
| 6766 | 11년 전 | 1269 | ||
| 6765 |
크림나이트
|
11년 전 | 1004 | |
| 6764 | 11년 전 | 1557 | ||
| 6763 | 11년 전 | 2612 | ||
| 6762 | 11년 전 | 541 | ||
| 6761 |
|
11년 전 | 791 | |
| 6760 |
|
11년 전 | 719 | |
| 6759 | 11년 전 | 3353 | ||
| 6758 | 11년 전 | 1008 | ||
| 6757 | 11년 전 | 1272 | ||
| 6756 | 11년 전 | 896 | ||
| 6755 |
|
11년 전 | 573 | |
| 6754 |
|
11년 전 | 725 | |
| 6753 |
|
11년 전 | 1389 | |
| 6752 | 11년 전 | 609 | ||
| 6751 |
|
11년 전 | 654 | |
| 6750 |
|
11년 전 | 2029 | |
| 6749 | 11년 전 | 1221 | ||
| 6748 |
|
11년 전 | 1123 | |
| 6747 | 11년 전 | 1175 | ||
| 6746 | 11년 전 | 841 | ||
| 6745 |
|
11년 전 | 916 | |
| 6744 | 11년 전 | 853 | ||
| 6743 | 11년 전 | 1297 | ||
| 6742 | 11년 전 | 541 | ||
| 6741 |
Abilityarch
|
11년 전 | 612 | |
| 6740 | 11년 전 | 659 | ||
| 6739 |
leewin20
|
11년 전 | 1237 | |
| 6738 | 11년 전 | 511 | ||
| 6737 | 11년 전 | 1219 | ||
| 6736 | 11년 전 | 1262 | ||
| 6735 | 11년 전 | 549 | ||
| 6734 | 11년 전 | 1288 | ||
| 6733 |
RipperTNT
|
11년 전 | 1844 | |
| 6732 |
|
11년 전 | 1340 | |
| 6731 |
|
11년 전 | 1397 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기