diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..cc86d43b 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 + //NO ESTE A FULL + 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.