큐1
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.dQ {
width: 200px;
height: 40px;
background-color: blue;
color: white;
text-align: right;
font-size: 35px;
line-height: 38px;
}
</style>
</head>
<body>
<div id="dQ" class="dQ"></div>
<script>
function OriginalQueue(qId) {
this.qId = qId;
this.qArray = [];
this.pushItem = function (qItem) { this.qArray.push(qItem); }
this.shiftItem = function () { }
this.countItems = function () { }
this.displayQueue = function () { document.getElementById("dQ").innerHTML += this.qArray; }
}
let zardQueue = new OriginalQueue("Zard");
zardQueue.pushItem("Z");
zardQueue.displayQueue();
</script>
</body>
</html>
A,B를 넣고 B를 빼기
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.dQ {
width: 200px;
height: 40px;
background-color: blue;
color: white;
text-align: right;
font-size: 35px;
line-height: 38px;
}
</style>
</head>
<body>
<div id="dQ" class="dQ"></div>
<script>
function OriginalQueue(qId) {
this.qId = qId;
this.qArray = [];
this.pushItem = function (qItem) {
this.qArray.push(qItem);
this.displayQueue();
alert("Push Item: " + qItem);
}
this.shiftItem = function () {
const shiftItem = this.qArray.shift();
this.displayQueue();
alert("Shift Item: " + shiftItem);
return shiftItem;
}
this.countItems = function () { }
this.displayQueue = function () {
document.getElementById("dQ").innerHTML = this.qArray;
}
}
let zardQueue = new OriginalQueue("Zard");
zardQueue.pushItem("A");
zardQueue.pushItem("B");
zardQueue.shiftItem();
</script>
</body>
</html>
'Javascript' 카테고리의 다른 글
predicate, forEach, Map, filter, Class, getter/setter 에 대해 알아보기 (0) | 2023.07.18 |
---|---|
MVC패턴, 화살표 함수, 전역객체, 디스트럭처링, ISO, 클로저 함수란 (0) | 2023.07.17 |
계산기 (0) | 2023.07.12 |
Vscode javascript로 객체 활용하여 계산기 만들기 (0) | 2023.07.11 |
아스키코드 활용 (0) | 2023.07.06 |