Skip to content

Commit bfa9340

Browse files
committed
feat: added length dicrease code on dequeue
1 parent 1f55c5d commit bfa9340

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Data-Structures/Queue/Queue.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class Queue {
5757
this.tail = null
5858
}
5959

60+
this.#size--
61+
6062
return firstData
6163
}
6264

Data-Structures/Queue/test/Queue.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Testing the Queue DS', () => {
1010
expect(queue.enqueue(9)).toBe(4)
1111
})
1212

13-
it('Testing length method', () => {
13+
it('Testing length after enqueue', () => {
1414
expect(queue.length).toBe(4)
1515
})
1616

@@ -28,6 +28,10 @@ describe('Testing the Queue DS', () => {
2828
expect(queue.dequeue()).toBe(2)
2929
})
3030

31+
it('Testing length after dequeue', () => {
32+
expect(queue.length).toBe(2)
33+
})
34+
3135
it('Testing isEmpty method', () => {
3236
const queue = new Queue()
3337
expect(queue.isEmpty()).toBeTruthy()

0 commit comments

Comments
 (0)