-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90e0665
commit 6141a66
Showing
4 changed files
with
24 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
// A queue is a list of objects that are inserted and removed first-in-first-out (FIFO). | ||
export default class Queue { | ||
constructor(items = []) { | ||
this.list = items | ||
} | ||
// Add to the front | ||
addToTop(item) { | ||
// Enqueue and add an item at the end of the queue. | ||
enqueue(item) { | ||
this.list.push(item) | ||
} | ||
// Add to the end | ||
addToBottom(item) { | ||
this.list.unshift(item) | ||
} | ||
// Removes and returns the last/newest item | ||
takeFromTop() { | ||
return this.list.pop() | ||
} | ||
// Removes and returns the first/oldest item | ||
takeFromBottom() { | ||
// Dequeue and remove an item at the front of the queue. | ||
dequeue() { | ||
return this.list.shift() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters