FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Interview-Question/Queue.js at master · shaantanu9/JavaScript-Interview-Question · GitHub
shaantanu9
/
JavaScript-Interview-Question
Public
forked from
namitmalasi/JavaScript-Interview-Question
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-Interview-Question
/
Queue.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (33 loc) · 768 Bytes
Breadcrumbs
JavaScript-Interview-Question
/
Queue.js
Copy path
File metadata and controls
39 lines (33 loc) · 768 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
class
Queue
{
constructor
(
)
{
this
.
items
=
[
]
;
this
.
head
=
0
;
this
.
tail
=
0
;
this
.
count
=
0
;
}
// adding the element to the queue
enqueue
(
element
)
{
this
.
items
[
this
.
tail
]
=
element
;
this
.
tail
++
;
this
.
count
++
;
}
// removing the element from the queue
dequeue
(
)
{
if
(
this
.
count
===
0
)
return
null
;
let
item
=
this
.
items
[
this
.
head
]
;
this
.
head
++
;
if
(
this
.
head
===
this
.
tail
)
{
this
.
head
=
0
;
this
.
tail
=
0
;
}
this
.
count
--
;
return
item
;
}
}
const
queue
=
new
Queue
(
)
;
queue
.
enqueue
(
10
)
;
queue
.
enqueue
(
20
)
;
queue
.
enqueue
(
30
)
;
console
.
log
(
queue
.
dequeue
(
)
)
;
// One main drawback in using this type of queue is the memory wastage.
// Circular queue can overcome this disadvantage.
Back
|
FazBrowse Home
|
New Git URL