From 364f54d41c52ba9e38b2b4c6486cf85b0442deaf Mon Sep 17 00:00:00 2001 From: jopen Date: Fri, 22 Aug 2025 22:27:33 +0200 Subject: [PATCH 1/2] falta logica queue y dom --- src/queue/queue-data-structure.js | 23 ++++++++++++++++------- src/stack/stack-data-structure.js | 24 ++++++++++++++++++------ src/stack/stack-dom.js | 2 +- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..7351d070 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -5,25 +5,34 @@ 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") + } else { + const queueElim = this.queueControl[0] + this.queueControl.shift() + return queueElim; + } + } display() { - // ... your code goes here - } + return [...this.queueControl]; //devuelve la copia +} } - // This is required to enable the automated tests, please ignore it. if (typeof module !== 'undefined') module.exports = Queue; diff --git a/src/stack/stack-data-structure.js b/src/stack/stack-data-structure.js index 1106f6f3..1d2995bc 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -5,24 +5,36 @@ class Stack { } canPush() { - // ... your code goes here + return (this.stackControl.length < this.MAX_SIZE) } + isEmpty() { - // ... your code goes here + return (this.stackControl.length === 0) } push(item) { - // ... your code goes here + if (this.canPush()) { + this.stackControl.push(item) + return this.stackControl; + } else { return 'Stack Overflow'} + } pop() { - // ... your code goes here + if (this.isEmpty()) { + return 'Stack Underflow'; + } else { + const stackElim = this.stackControl[this.stackControl.length - 1] + this.stackControl.pop() + return stackElim; + } } + display() { - // ... your code goes here - } + return [...this.stackControl]; +} } // This is required to enable the automated tests, please ignore it. diff --git a/src/stack/stack-dom.js b/src/stack/stack-dom.js index db661587..14c857d1 100644 --- a/src/stack/stack-dom.js +++ b/src/stack/stack-dom.js @@ -6,7 +6,7 @@ const warningBottomStack = document.querySelector('#stack-container .warning-bot const addStackBtn = document.getElementById('add-stack'); const takeStackBtn = document.getElementById('take-stack'); -const newStack = new Stack(); +const newStack = new Stack(); //definimos la clase const clearStackInput = () => { stackInput.value = ''; From b4e87269366f9fbad410ec113908679d7e9177dd Mon Sep 17 00:00:00 2001 From: jopen Date: Sat, 23 Aug 2025 10:17:06 +0200 Subject: [PATCH 2/2] Ejercicio completo --- src/queue/queue-dom.js | 48 +++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/queue/queue-dom.js b/src/queue/queue-dom.js index 236675b7..998573ee 100644 --- a/src/queue/queue-dom.js +++ b/src/queue/queue-dom.js @@ -10,36 +10,68 @@ const dequeue = document.querySelector('.btn-take-dequeue'); const queue = new Queue(); const clearQueueInput = () => { - // ... your code goes here + queueInput.value = ''; }; const generateListQueue = () => { - // ... your code goes here + + warningBottomQueue.style.display = 'none'; + warningTopQueue.style.display = 'none'; + queueUL.innerHTML = ''; + + //calculo longitud del array de elementos (display), + //calculo el espacio que queda sin ocupar para dejarlo vacio + + let length = queue.display().length + let size = queue.MAX_SIZE - length + + for (let i = 0; i < length; i++) { + let queueLI = document.createElement("li"); + queueLI.className = 'active'; + queueLI.innerText = queue.display()[i]; + queueUL.appendChild(queueLI); + }; + for (let i = 0; i < size; i++) { + let queueLI = document.createElement("li"); + queueLI.className = 'inactive' + queueLI.innerHTML = ' '; + queueUL.appendChild(queueLI) }; +} generateListQueue(); const generateWarningQueue = (type) => { if (type === 'underflow') { - // ... your code goes here + warningBottomQueue.style.display = 'block' + warningBottomQueue.innerHTML = "underflow" + } else if (type === 'overflow') { - // ... your code goes here + warningTopQueue.style.display = 'block' + warningTopQueue.innerHTML = "overflow" } }; const addToQueue = () => { try { - // ... your code goes here + queue.enqueue(queueInput.value); + generateListQueue() + clearQueueInput() + } catch (error) { - // there was an overflow error, handle it + console.error("QUEUE_OVERFLOW") + generateWarningQueue('overflow') } }; const removeFromQueue = () => { try { - // ... your code goes here + queue.dequeue() + generateListQueue() + } catch (error) { - // there was an underflow error, handle it + console.error("QUEUE_UNDERFLOW") + generateWarningQueue("underflow") } };