From 4b0aa0427e8682f6dcff535940234c51f68b3289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CRaquel?= <“raquel.torre.oporto@gmail.com”> Date: Tue, 17 Oct 2023 18:20:33 +0200 Subject: [PATCH 1/2] solved lab --- src/queue/queue-data-structure.js | 40 ++++++++++++++++++++++++++----- src/stack/stack-data-structure.js | 36 +++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..5c0b2537 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -5,24 +5,52 @@ class Queue { } canEnqueue() { - // ... your code goes here + if (this.queueControl.length >= this.MAX_SIZE) { + return false + } else { + return true + } } isEmpty() { - // ... your code goes here + if (this.queueControl <= 0) { + return true + } else { + return false + } } enqueue(item) { - // ... your code goes here + + if (!this.canEnqueue()) { + throw new Error('QUEUE_OVERFLOW') + } else { + this.queueControl.push(item) + } + return this.queueControl } + + + + + dequeue() { - // ... your code goes here + if (this.isEmpty()) { + throw new Error('QUEUE_UNDERFLOW') + } else { + this.queueControl.pop() + + } + return this.queueControl.pop() } + z 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..43f9de01 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -5,24 +5,48 @@ class Stack { } canPush() { - // ... your code goes here + if (this.stackControl.length >= this.MAX_SIZE) { + return false + } else { + return true + } } isEmpty() { - // ... your code goes here + if (this.stackControl.length > 0) { + return false + } else { + return true + } } push(item) { - // ... your code goes here + + + if (!this.canPush()) { + throw new Error('STACK_OVERFLOW'); + } else { + this.stackControl.push(item) + return this.stackControl + } + + } pop() { - // ... your code goes here + + if (this.isEmpty()) { + throw new Error('STACK_UNDERFLOW'); + + } else { + return this.stackControl.pop() + } + } display() { - // ... your code goes here - } + return this.stackControl + } } // This is required to enable the automated tests, please ignore it. From 83d46ebeddaedf751f9cd4c4a4a1941cc862fdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CRaquel?= <“raquel.torre.oporto@gmail.com”> Date: Tue, 17 Oct 2023 18:25:23 +0200 Subject: [PATCH 2/2] done --- src/queue/queue-data-structure.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 5c0b2537..cc86d43b 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -21,7 +21,7 @@ class Queue { } enqueue(item) { - + //NO ESTE A FULL if (!this.canEnqueue()) { throw new Error('QUEUE_OVERFLOW') } else {