<?
/*
큐(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();
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7230 | 11년 전 | 3614 | ||
| 7229 | 11년 전 | 3741 | ||
| 7228 | 11년 전 | 3783 | ||
| 7227 | 11년 전 | 3909 | ||
| 7226 | 11년 전 | 2363 | ||
| 7225 | 11년 전 | 17448 | ||
| 7224 |
AngryDev
|
11년 전 | 1352 | |
| 7223 |
돌아온깡통
|
11년 전 | 1095 | |
| 7222 |
돌아온깡통
|
11년 전 | 1038 | |
| 7221 |
돌아온깡통
|
11년 전 | 881 | |
| 7220 |
돌아온깡통
|
11년 전 | 1004 | |
| 7219 |
돌아온깡통
|
11년 전 | 835 | |
| 7218 |
돌아온깡통
|
11년 전 | 662 | |
| 7217 |
돌아온깡통
|
11년 전 | 1046 | |
| 7216 |
돌아온깡통
|
11년 전 | 790 | |
| 7215 |
돌아온깡통
|
11년 전 | 702 | |
| 7214 |
돌아온깡통
|
11년 전 | 1052 | |
| 7213 |
돌아온깡통
|
11년 전 | 920 | |
| 7212 |
돌아온깡통
|
11년 전 | 713 | |
| 7211 |
돌아온깡통
|
11년 전 | 866 | |
| 7210 |
돌아온깡통
|
11년 전 | 888 | |
| 7209 |
돌아온깡통
|
11년 전 | 890 | |
| 7208 |
돌아온깡통
|
11년 전 | 1002 | |
| 7207 |
돌아온깡통
|
11년 전 | 623 | |
| 7206 |
돌아온깡통
|
11년 전 | 676 | |
| 7205 |
돌아온깡통
|
11년 전 | 861 | |
| 7204 |
돌아온깡통
|
11년 전 | 719 | |
| 7203 |
돌아온깡통
|
11년 전 | 744 | |
| 7202 |
돌아온깡통
|
11년 전 | 710 | |
| 7201 |
돌아온깡통
|
11년 전 | 660 | |
| 7200 |
돌아온깡통
|
11년 전 | 704 | |
| 7199 |
돌아온깡통
|
11년 전 | 1318 | |
| 7198 |
돌아온깡통
|
11년 전 | 647 | |
| 7197 |
돌아온깡통
|
11년 전 | 964 | |
| 7196 |
돌아온깡통
|
11년 전 | 861 | |
| 7195 |
돌아온깡통
|
11년 전 | 605 | |
| 7194 |
돌아온깡통
|
11년 전 | 632 | |
| 7193 |
돌아온깡통
|
11년 전 | 699 | |
| 7192 |
돌아온깡통
|
11년 전 | 727 | |
| 7191 |
joe031
|
11년 전 | 1255 | |
| 7190 | 11년 전 | 4148 | ||
| 7189 | 11년 전 | 1233 | ||
| 7188 |
잘살아보자
|
11년 전 | 950 | |
| 7187 | 11년 전 | 1426 | ||
| 7186 |
kiplayer
|
11년 전 | 7543 | |
| 7185 | 11년 전 | 1133 | ||
| 7184 |
잘살아보자
|
11년 전 | 2332 | |
| 7183 |
잘살아보자
|
11년 전 | 1145 | |
| 7182 |
잘살아보자
|
11년 전 | 1209 | |
| 7181 | 11년 전 | 1486 | ||
| 7180 |
하얀비요일
|
11년 전 | 983 | |
| 7179 |
잘살아보자
|
11년 전 | 981 | |
| 7178 | 11년 전 | 976 | ||
| 7177 | 11년 전 | 1001 | ||
| 7176 | 11년 전 | 1659 | ||
| 7175 |
|
11년 전 | 1044 | |
| 7174 |
kiplayer
|
11년 전 | 1172 | |
| 7173 | 11년 전 | 959 | ||
| 7172 |
잘살아보자
|
11년 전 | 4642 | |
| 7171 |
잘살아보자
|
11년 전 | 701 | |
| 7170 | 11년 전 | 1066 | ||
| 7169 |
초심의설렘
|
11년 전 | 1467 | |
| 7168 | 11년 전 | 1003 | ||
| 7167 |
잘살아보자
|
11년 전 | 5282 | |
| 7166 |
잘살아보자
|
11년 전 | 3428 | |
| 7165 | 11년 전 | 4950 | ||
| 7164 | 11년 전 | 824 | ||
| 7163 | 11년 전 | 1194 | ||
| 7162 |
울라라라우
|
11년 전 | 1380 | |
| 7161 | 11년 전 | 1256 | ||
| 7160 |
skyler
|
11년 전 | 1187 | |
| 7159 |
|
11년 전 | 694 | |
| 7158 |
|
11년 전 | 3351 | |
| 7157 |
잘살아보자
|
11년 전 | 2891 | |
| 7156 |
잘살아보자
|
11년 전 | 2221 | |
| 7155 |
잘살아보자
|
11년 전 | 1448 | |
| 7154 |
잘살아보자
|
11년 전 | 1447 | |
| 7153 | 11년 전 | 2886 | ||
| 7152 |
울라라라우
|
11년 전 | 827 | |
| 7151 | 11년 전 | 1054 | ||
| 7150 |
잘살아보자
|
11년 전 | 2384 | |
| 7149 |
잘살아보자
|
11년 전 | 3289 | |
| 7148 |
잘살아보자
|
11년 전 | 1189 | |
| 7147 |
잘살아보자
|
11년 전 | 755 | |
| 7146 |
잘살아보자
|
11년 전 | 1397 | |
| 7145 |
잘살아보자
|
11년 전 | 708 | |
| 7144 |
잘살아보자
|
11년 전 | 1301 | |
| 7143 |
잘살아보자
|
11년 전 | 756 | |
| 7142 |
잘살아보자
|
11년 전 | 1446 | |
| 7141 |
잘살아보자
|
11년 전 | 1197 | |
| 7140 |
잘살아보자
|
11년 전 | 2006 | |
| 7139 |
잘살아보자
|
11년 전 | 3669 | |
| 7138 |
잘살아보자
|
11년 전 | 3163 | |
| 7137 |
잘살아보자
|
11년 전 | 3627 | |
| 7136 |
잘살아보자
|
11년 전 | 1381 | |
| 7135 |
gooroo
|
11년 전 | 1611 | |
| 7134 |
열라뽕똬이
|
11년 전 | 2315 | |
| 7133 |
|
11년 전 | 1015 | |
| 7132 | 11년 전 | 1425 | ||
| 7131 | 11년 전 | 3568 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기