Skip to content

Commit 53ac17a

Browse files
committed
--fix : fix doublyLinkedList length
1 parent 84feda9 commit 53ac17a

File tree

1 file changed

+7
-9
lines changed
  • src/_DataStructures_/DoublyLinkedList

1 file changed

+7
-9
lines changed

src/_DataStructures_/DoublyLinkedList/index.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class Node {
44
this.data = data;
55
this.previous = previous;
66
this.next = next;
7-
this.length = 0;
87
}
98
}
109

@@ -16,30 +15,31 @@ class DoublyLinkedList {
1615
this.tail = new Node(null, null, null);
1716
this.head.next = this.tail; // head next point to tail
1817
this.tail.previous = this.head; // tail previous point to head
18+
this.size = 0;
1919
}
2020

2121
addAtBeginning(value) {
2222
const newNode = new Node(value, this.head, this.head.next);
2323
this.head.next.previous = newNode;
2424
this.head.next = newNode;
25-
this.length += 1;
25+
this.size += 1;
2626
}
2727

2828
addAtEnd(value) {
2929
const newNode = new Node(value, this.tail.previous, this.tail);
3030
this.tail.previous.next = newNode;
3131
this.tail.previous = newNode;
32-
this.length += 1;
32+
this.size += 1;
3333
}
3434

3535
removeAtBeginning() {
3636
this.remove(this.head.next);
37-
this.length -= 1;
37+
this.size -= 1;
3838
}
3939

4040
removeAtEnd() {
4141
this.remove(this.tail.previous);
42-
this.length -= 1;
42+
this.size -= 1;
4343
}
4444

4545
remove(node) {
@@ -50,7 +50,7 @@ class DoublyLinkedList {
5050
}
5151

5252
length() {
53-
return this.length;
53+
return this.size;
5454
}
5555

5656
display() {
@@ -62,6 +62,4 @@ class DoublyLinkedList {
6262
}
6363
}
6464

65-
module.exports = {
66-
DoublyLinkedList,
67-
};
65+
module.exports = DoublyLinkedList;

0 commit comments

Comments
 (0)