-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R Melookaran #4
base: master
Are you sure you want to change the base?
R Melookaran #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 Your implementations looks good Roslyn. Let me know what questions you have.
Apologies for the extremely delayed feedback.
🟢
this.capacity = 20; | ||
this.head = 0; | ||
this.tail = 0; | ||
this.store = Array(this.capacity).fill(null); | ||
} | ||
|
||
enqueue(element) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
if (this.size()!==this.capacity) { | ||
this.store[this.tail] = element; | ||
this.tail = (this.tail + 1) % this.capacity; | ||
} | ||
} | ||
|
||
dequeue() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
this.store[this.head] = null; | ||
this.head = (this.head + 1) % this.capacity; | ||
return dequeued; | ||
} | ||
} | ||
|
||
front() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 We want to return the value at the front of the queue, not the index
} | ||
|
||
front() { | ||
throw new Error("This method has not been implemented!"); | ||
return this.head | ||
} | ||
|
||
size() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
} else { | ||
size = this.tail - this.head; | ||
} | ||
return size; | ||
} | ||
|
||
isEmpty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
} | ||
|
||
push() { | ||
throw new Error("This method has not been implemented!"); | ||
push(value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
push() { | ||
throw new Error("This method has not been implemented!"); | ||
push(value) { | ||
this.store.addFirst(value); | ||
} | ||
|
||
pop() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
throw new Error("This method has not been implemented!"); | ||
const first = this.store.getFirst(); | ||
this.store.delete(first); | ||
return first; | ||
} | ||
|
||
isEmpty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 This works, however LinkedList also has an empty
method you could take advantage of
Fixed pickups.