Repository navigation
Expand file tree
/
Copy pathqueue.html
More file actions
78 lines (70 loc) · 3.28 KB
/
Copy pathqueue.html
File metadata and controls
78 lines (70 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>실습: 큐 | 자료구조</title>
<link rel="stylesheet" href="../css/common.css">
</head>
<body>
<header class="header">
<h1>실습: 큐 (줄 서기)</h1>
<p class="subtitle">뒤에 서고, 맨 앞 사람만 나가기</p>
<div id="theme-switcher-wrap"></div>
</header>
<main class="practice-page">
<a href="../index.html" class="back">← 목차</a>
<a href="../lectures/02-2-큐.html" class="back">II단원 2. 큐 (강의)</a>
<div class="practice-explanation" style="background: var(--callout-etymology-bg); border-left: 4px solid var(--callout-etymology-border); padding: 0.75rem 1rem; margin: 0.75rem 0; border-radius: 0 8px 8px 0;">
<p><strong>큐</strong> = 뒤에 넣고, 앞에서만 뺌. <strong>FIFO</strong>(먼저 넣은 게 먼저 나옴). 연산: enqueue → <code>deque.append(값)</code>, dequeue → <code>deque.popleft()</code>. <strong>응용</strong> 대사 한 줄씩 나오는 창, BFS(가까운 정점부터 탐색), 프린터 대기열.</p>
</div>
<p>줄 서기와 같아요. <strong>뒤에 넣기</strong>를 누르면 줄 맨 뒤에 서고, <strong>앞에서 꺼내기</strong>를 누르면 <strong>맨 앞에 있는 사람만</strong> 나가요. 먼저 줄 선 사람이 먼저 나가는지 확인해 보세요.</p>
<div class="controls">
<input type="text" id="inputVal" placeholder="넣을 값 (예: 1번)" maxlength="6" aria-label="큐에 넣을 값">
<button type="button" id="btnEnqueue">뒤에 넣기 (Enqueue)</button>
<button type="button" id="btnDequeue">앞에서 꺼내기 (Dequeue)</button>
</div>
<div class="viz" id="viz" role="status" aria-live="polite">
[ 맨 앞 ] — 비어 있음 — [ 맨 뒤 ]
</div>
<p class="hint">방금 나간 값: <strong id="lastDeq">—</strong></p>
</main>
<script>
(function () {
var queue = [];
var viz = document.getElementById('viz');
var lastDeq = document.getElementById('lastDeq');
var inputVal = document.getElementById('inputVal');
function render() {
if (queue.length === 0) {
viz.innerHTML = '[ 맨 앞 ] — 비어 있음 — [ 맨 뒤 ]';
return;
}
var items = queue.map(function (x, i) {
var label = (i === 0 ? ' Front ' : '') + (i === queue.length - 1 ? ' Rear' : '');
return '<span class="viz-item">' + x + label + '</span>';
}).join('');
viz.innerHTML = '<div style="display:flex; flex-wrap:wrap; align-items:center;">' + items + '</div>';
}
document.getElementById('btnEnqueue').addEventListener('click', function () {
var v = inputVal.value.trim();
if (v === '') return;
queue.push(v);
inputVal.value = '';
render();
});
document.getElementById('btnDequeue').addEventListener('click', function () {
if (queue.length === 0) {
lastDeq.textContent = '(비어 있음)';
return;
}
var v = queue.shift();
lastDeq.textContent = v;
render();
});
render();
})();
</script>
<script src="../js/theme.js"></script>
</body>
</html>