diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..530345c9 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -6,21 +6,47 @@ class Queue { canEnqueue() { // ... your code goes here + if(this.queueControl.length { - // ... your code goes here + queueInput.value = ''; }; const generateListQueue = () => { - // ... your code goes here + warningTopQueue.style.display = 'none'; + warningBottomQueue.style.display = 'none'; + queueUL.innerHTML = ''; + let length = queue.display().length; + let size = queue.MAX_SIZE - length; + + queue.display().forEach(item => { + let li = document.createElement('li'); + li.className = 'active'; + li.innerText = item; + queueUL.appendChild(li); + }); + + for (let i = 0; i < size; i++) { + let li = document.createElement('li'); + li.className = 'inactive'; + li.innerHTML = ' '; + queueUL.appendChild(li); + } }; + generateListQueue(); + const generateWarningQueue = (type) => { if (type === 'underflow') { - // ... your code goes here + warningBottomQueue.style.display = 'block'; + warningBottomQueue.innerText = type; } else if (type === 'overflow') { - // ... your code goes here + warningTopQueue.style.display = 'block'; + warningTopQueue.innerText = type; } }; const addToQueue = () => { try { - // ... your code goes here + queue.enqueue(queueInput.value) + clearQueueInput(); + generateListQueue() } catch (error) { - // there was an overflow error, handle it + generateWarningQueue('overflow∫') } }; const removeFromQueue = () => { try { - // ... your code goes here + queue.dequeue() + generateListQueue() } catch (error) { - // there was an underflow error, handle it + generateWarningQueue('underflow') } }; diff --git a/src/stack/stack-data-structure.js b/src/stack/stack-data-structure.js index 1106f6f3..3461c093 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -6,22 +6,50 @@ 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 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()){ + + return this.stackControl.pop() + } + else{ + throw new Error('STACK_UNDERFLOW') + } } display() { // ... your code goes here + return this.stackControl } }