Skip to content
Open

solved #1129

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/queue/queue-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@ class Queue {
}

canEnqueue() {
// ... your code goes here
}
return this.queueControl.length < this.MAX_SIZE
}

isEmpty() {
// ... your code goes here
return this.queueControl.length === 0
}

enqueue(item) {
// ... your code goes here
if(this.canEnqueue()){
this.queueControl.push(item)
return this.queueControl
}
else{
throw new Error('QUEUE_OVERFLOW')
}
}

dequeue() {
// ... your code goes here
if(this.isEmpty()){
throw new Error('QUEUE_UNDERFLOW');
}
return this.queueControl.shift()
}

display() {
// ... your code goes here
return this.queueControl
}
}

Expand Down
25 changes: 17 additions & 8 deletions src/stack/stack-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@ class Stack {
}

canPush() {
// ... your code goes here
return this.stackControl.length < this.MAX_SIZE
}

isEmpty() {
// ... your code goes here
}

push(item) {
// ... your code goes here
return this.stackControl.length === 0
}

push(item){
if(this.canPush()){
this.stackControl.push(item)
return this.stackControl
}
else {
throw new Error('STACK_OVERFLOW')
}
}

pop() {
// ... your code goes here
if(this.isEmpty()){
throw new Error('STACK_UNDERFLOW');
}
return this.stackControl.pop()
}

display() {
// ... your code goes here
return this.stackControl
}
}

Expand Down