-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.js
More file actions
56 lines (46 loc) · 1.18 KB
/
Queue.js
File metadata and controls
56 lines (46 loc) · 1.18 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
module.exports = class Queue{
constructor(){
this.data = []
console.log("큐가 생성되었습니다.")
}
enqueue(element){
//여기서 push함수는 Array의 내장함수이다.
//요소를 배열 맨 뒤에 삽입.
this.data.push(element);
}
pop(){
//shift는 Array의 내장함수이다.
//배열내의 맨 앞 요소를 반환하고 배열내에서 삭제한다.
return this.data.shift();
}
//큐의 맨 젓번째 요소 반환
front(){
return this.data[0];
}
//큐의 맨 끝 요소 반환
back(){
return this.data[this.data.length-1];
}
//큐에 저장된 요소 모두 출력
toString(){
let q="";
for(let i=0; i<this.data.length; i++)
{
q = q + this.data[i] + ", ";
}
return q
}
//큐 사이즈 반환
size(){
return this.data.length
}
//큐 비우기
clear(){
if(this.data.length==0){
return true;
}
else{
return false;
}
}
}