From 6603df0366e3d426083fad8333a9fb61d0e24f96 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 17 Oct 2023 18:15:05 +0200 Subject: [PATCH] done --- src/queue/queue-data-structure.js | 29 ++++++++++++++++++++------ src/stack/stack-data-structure.js | 34 +++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..80a8b4ee 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -5,24 +5,41 @@ class Queue { } canEnqueue() { - // ... your code goes here + if (this.queueControl.length < this.MAX_SIZE) { + return true + } else { + return false + } } isEmpty() { - // ... your code goes here + if (this.queueControl.length === 0) { + return true + } else { + return false + } } 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() === false) { + return this.queueControl.shift() + } else { + 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..bc5c6684 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -5,25 +5,43 @@ class Stack { } canPush() { - // ... your code goes here + if (this.stackControl.length < this.MAX_SIZE) { + return true + } else { + return false + + } } + isEmpty() { - // ... your code goes here + if (this.stackControl.length == 0) { + return true + } else { + return false + } } push(item) { - // ... your code goes here + if (this.canPush()) { + this.stackControl.push(item) + return this.stackControl + } else { + throw new Error('STACK_OVERFLOW') + } } pop() { - // ... your code goes here + if (this.isEmpty() === false) { + return this.stackControl.pop() + } else { + throw new Error('STACK_UNDERFLOW') + } } - display() { - // ... your code goes here - } -} + return this.stackControl + } +} // This is required to enable the automated tests, please ignore it. if (typeof module !== 'undefined') module.exports = Stack;