File tree 1 file changed +7
-9
lines changed
src/_DataStructures_/DoublyLinkedList
1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ class Node {
4
4
this . data = data ;
5
5
this . previous = previous ;
6
6
this . next = next ;
7
- this . length = 0 ;
8
7
}
9
8
}
10
9
@@ -16,30 +15,31 @@ class DoublyLinkedList {
16
15
this . tail = new Node ( null , null , null ) ;
17
16
this . head . next = this . tail ; // head next point to tail
18
17
this . tail . previous = this . head ; // tail previous point to head
18
+ this . size = 0 ;
19
19
}
20
20
21
21
addAtBeginning ( value ) {
22
22
const newNode = new Node ( value , this . head , this . head . next ) ;
23
23
this . head . next . previous = newNode ;
24
24
this . head . next = newNode ;
25
- this . length += 1 ;
25
+ this . size += 1 ;
26
26
}
27
27
28
28
addAtEnd ( value ) {
29
29
const newNode = new Node ( value , this . tail . previous , this . tail ) ;
30
30
this . tail . previous . next = newNode ;
31
31
this . tail . previous = newNode ;
32
- this . length += 1 ;
32
+ this . size += 1 ;
33
33
}
34
34
35
35
removeAtBeginning ( ) {
36
36
this . remove ( this . head . next ) ;
37
- this . length -= 1 ;
37
+ this . size -= 1 ;
38
38
}
39
39
40
40
removeAtEnd ( ) {
41
41
this . remove ( this . tail . previous ) ;
42
- this . length -= 1 ;
42
+ this . size -= 1 ;
43
43
}
44
44
45
45
remove ( node ) {
@@ -50,7 +50,7 @@ class DoublyLinkedList {
50
50
}
51
51
52
52
length ( ) {
53
- return this . length ;
53
+ return this . size ;
54
54
}
55
55
56
56
display ( ) {
@@ -62,6 +62,4 @@ class DoublyLinkedList {
62
62
}
63
63
}
64
64
65
- module . exports = {
66
- DoublyLinkedList,
67
- } ;
65
+ module . exports = DoublyLinkedList ;
You can’t perform that action at this time.
0 commit comments