From 3d68bdc0267676eaa8314c302017567e2fdf984f Mon Sep 17 00:00:00 2001 From: Martin Beacham Date: Sat, 30 Mar 2024 13:28:11 -0400 Subject: [PATCH 1/3] Update CircularQueue.js --- Data-Structures/Queue/CircularQueue.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Data-Structures/Queue/CircularQueue.js b/Data-Structures/Queue/CircularQueue.js index 27f2196780..b71d7b5b54 100644 --- a/Data-Structures/Queue/CircularQueue.js +++ b/Data-Structures/Queue/CircularQueue.js @@ -77,7 +77,11 @@ class CircularQueue { // Displays the length of queue length() { - return this.queue.length - 1 + if (this.queue.length > 0) { + return this.queue.length - 1 + } else { + return 0 + } } // Display the top most value of queue From 7adf170811309df907db7e2ea9d73348ca89b775 Mon Sep 17 00:00:00 2001 From: Martin Beacham Date: Sat, 30 Mar 2024 16:55:16 -0400 Subject: [PATCH 2/3] Update CircularQueue.js Taking comments into account for refactoring my change. --- Data-Structures/Queue/CircularQueue.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Data-Structures/Queue/CircularQueue.js b/Data-Structures/Queue/CircularQueue.js index b71d7b5b54..ab666d1614 100644 --- a/Data-Structures/Queue/CircularQueue.js +++ b/Data-Structures/Queue/CircularQueue.js @@ -77,11 +77,7 @@ class CircularQueue { // Displays the length of queue length() { - if (this.queue.length > 0) { - return this.queue.length - 1 - } else { - return 0 - } + return checkEmpty() ? 0 : this.queue.length - 1 } // Display the top most value of queue From d8323c829dab2c0358a85283e915394dddb25e76 Mon Sep 17 00:00:00 2001 From: Martin Beacham Date: Sat, 30 Mar 2024 16:57:10 -0400 Subject: [PATCH 3/3] Update CircularQueue.js Adding "this" to checkEmpty() --- Data-Structures/Queue/CircularQueue.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Data-Structures/Queue/CircularQueue.js b/Data-Structures/Queue/CircularQueue.js index ab666d1614..c716251668 100644 --- a/Data-Structures/Queue/CircularQueue.js +++ b/Data-Structures/Queue/CircularQueue.js @@ -77,7 +77,7 @@ class CircularQueue { // Displays the length of queue length() { - return checkEmpty() ? 0 : this.queue.length - 1 + return this.checkEmpty() ? 0 : this.queue.length - 1 } // Display the top most value of queue