From 76ba7e56c6a2c4e66dcb3239dad0f715520baa7d Mon Sep 17 00:00:00 2001 From: Marina Viejo <100945399+marinavp8@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:47:13 +0200 Subject: [PATCH] done --- src/queue/queue-data-structure.js | 21 ++++++++++++++++++++- src/stack/stack-data-structure.js | 21 ++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) 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.