diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..e4ab9ce6 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -6,23 +6,42 @@ class Queue { canEnqueue() { // ... your code goes here + if (this.queueControl.length === this.MAX_SIZE) { + return false + } + return true } isEmpty() { // ... your code goes here + if (this.queueControl.length === 0) { + return true + } + return false } enqueue(item) { // ... your code goes here + if (this.queueControl.length === this.MAX_SIZE) { + throw new Error('QUEUE_OVERFLOW'); + } + this.queueControl.push(item) + return this.queueControl + } dequeue() { // ... your code goes here + if (this.queueControl.length > 0) { + return this.queueControl.shift() + } + throw new Error('QUEUE_UNDERFLOW') } display() { // ... your code goes here - } + return this.queueControl + } } // This is required to enable the automated tests, please ignore it. diff --git a/src/stack/stack-data-structure.js b/src/stack/stack-data-structure.js index 1106f6f3..12faa4b2 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -6,23 +6,42 @@ class Stack { canPush() { // ... your code goes here + if (this.stackControl.length === this.MAX_SIZE) { + return false + } + return true } isEmpty() { // ... your code goes here + if (this.stackControl.length === 0) { + return true + } + return false } push(item) { // ... your code goes here + if (this.stackControl.length === this.MAX_SIZE) { + throw new Error('STACK_OVERFLOW') + } else { + this.stackControl.push(item) + return this.stackControl + } } pop() { // ... your code goes here + if (this.stackControl.length === 0) { + throw new Error('STACK_UNDERFLOW') + } + return this.stackControl.pop() } display() { // ... your code goes here - } + return this.stackControl + } } // This is required to enable the automated tests, please ignore it.