diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..3b479bb1 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -5,23 +5,32 @@ 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'); + } + return this.queueControl.shift() } display() { - // ... your code goes here + return this.queueControl } } diff --git a/src/stack/stack-data-structure.js b/src/stack/stack-data-structure.js index 1106f6f3..e0c83389 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -5,23 +5,32 @@ class Stack { } canPush() { - // ... your code goes here + return this.stackControl.length < this.MAX_SIZE } isEmpty() { - // ... your code goes here - } - - push(item) { - // ... your code goes here + return this.stackControl.length === 0 } + + push(item){ + if(this.canPush()){ + this.stackControl.push(item) + return this.stackControl + } + else { + throw new Error('STACK_OVERFLOW') + } +} pop() { - // ... your code goes here + if(this.isEmpty()){ + throw new Error('STACK_UNDERFLOW'); + } + return this.stackControl.pop() } display() { - // ... your code goes here + return this.stackControl } }