From cddf4bdb6e44077d03f0125872a6c191785f2cd9 Mon Sep 17 00:00:00 2001 From: Madhushree B Date: Thu, 7 Mar 2024 17:18:55 +0100 Subject: [PATCH 1/4] Iteration 1 --- src/stack/stack-data-structure.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/stack/stack-data-structure.js b/src/stack/stack-data-structure.js index 1106f6f3..6171aefa 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -6,22 +6,47 @@ class Stack { canPush() { // ... your code goes here + if(this.stackControl.length < this.MAX_SIZE){ + return true; + } else { + return false; + } } isEmpty() { // ... your code goes here - } + if(this.stackControl > 0) { + return false + } else { + return true; + } + } push(item) { // ... your code goes here + if(this.canPush() === true){ + this.stackControl.push(item); + return this.stackControl; + + } else { + throw new Error("STACK_OVERFLOW") + } } pop() { // ... your code goes here + if(this.isEmpty() === false ){ + this.stackControl.pop(); + return this.stackControl; + // TO DO + } else { + throw new Error("STACK_UNDERFLOW") + } } display() { // ... your code goes here + return this.stackControl; } } From 0d892154d60363eac20882bb3d249c0c8a3fbc3e Mon Sep 17 00:00:00 2001 From: Madhushree B Date: Thu, 7 Mar 2024 17:29:07 +0100 Subject: [PATCH 2/4] changes in the 1st Iteration --- src/stack/stack-data-structure.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/stack/stack-data-structure.js b/src/stack/stack-data-structure.js index 6171aefa..b48b9f0b 100644 --- a/src/stack/stack-data-structure.js +++ b/src/stack/stack-data-structure.js @@ -15,11 +15,7 @@ class Stack { isEmpty() { // ... your code goes here - if(this.stackControl > 0) { - return false - } else { - return true; - } + return this.stackControl.length === 0; } push(item) { @@ -27,7 +23,6 @@ class Stack { if(this.canPush() === true){ this.stackControl.push(item); return this.stackControl; - } else { throw new Error("STACK_OVERFLOW") } @@ -35,12 +30,10 @@ class Stack { pop() { // ... your code goes here - if(this.isEmpty() === false ){ - this.stackControl.pop(); - return this.stackControl; - // TO DO + if (this.isEmpty() === false) { + return this.stackControl.pop(); } else { - throw new Error("STACK_UNDERFLOW") + throw new Error("STACK_UNDERFLOW"); } } From 1b9512b4842cea3b941933a4aa2cd7891f306e50 Mon Sep 17 00:00:00 2001 From: Madhushree B Date: Thu, 7 Mar 2024 17:39:16 +0100 Subject: [PATCH 3/4] Iteration 2 --- src/queue/queue-data-structure.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/queue/queue-data-structure.js b/src/queue/queue-data-structure.js index 98ac0fd0..209b10eb 100644 --- a/src/queue/queue-data-structure.js +++ b/src/queue/queue-data-structure.js @@ -6,22 +6,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() === false){ + throw new Error('QUEUE_OVERFLOW') + } + this.queueControl.push(item); + return this.queueControl; } dequeue() { // ... your code goes here + if(this.isEmpty() === true){ + throw new Error('QUEUE_UNDERFLOW') + } + return this.queueControl.shift(); } display() { // ... your code goes here + return this.queueControl; } } From 34c0d0a0e8a9530897ce8953d9b95fb1b59a0966 Mon Sep 17 00:00:00 2001 From: Madhushree B Date: Wed, 20 Mar 2024 15:57:07 +0100 Subject: [PATCH 4/4] iteration 1 & 2 --- index.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.html b/index.html index 3fab1ac7..74d54a96 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,7 @@

Stack

placeholder="Add element to the stack" /> + + +
    +
    @@ -59,6 +63,7 @@

    Queue

    placeholder="Add element to the queue" />
    + +