0% found this document useful (0 votes)
5 views1 page

JavaScript Queue Class Implementation

The document defines a Queue class that manages a private array of items. It includes methods for adding (enqueue), removing (dequeue), checking if the queue is empty, retrieving the front item, and getting the length of the queue. The class also has a method to format the items into a string for display.

Uploaded by

Rehan Hussain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

JavaScript Queue Class Implementation

The document defines a Queue class that manages a private array of items. It includes methods for adding (enqueue), removing (dequeue), checking if the queue is empty, retrieving the front item, and getting the length of the queue. The class also has a method to format the items into a string for display.

Uploaded by

Rehan Hussain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

}

get length() {
return this.#[Link]
}

getItems() {
return this.#items
}

prettify() {
let resultString = ''
for(let i = 0; i < this.#[Link]; i++)
resultString += this.#items[i] + ' '
return resultString
}
}

Now that we’ve defined the class, we need to export it:

class Queue {
#items = []

enqueue(item) {
this.#[Link](item)
}

dequeue() {
if([Link]())
return 'Underflow'
return this.#[Link]()
}

isEmpty() {
return this.#[Link] === 0
}

front() {
if([Link]())
return 'No item in queue'
return this.#items[0]
}

get length() {
return this.#[Link]

104

You might also like