1
1
function DoublyLinkedList ( ) {
2
2
3
- var Node = function ( element ) {
3
+ let Node = function ( element ) {
4
4
5
5
this . element = element ;
6
6
this . next = null ;
7
7
this . prev = null ; //NEW
8
8
} ;
9
9
10
- var length = 0 ;
11
- var head = null ;
12
- var tail = null ; //NEW
10
+ let length = 0 ;
11
+ let head = null ;
12
+ let tail = null ; //NEW
13
13
14
14
this . append = function ( element ) {
15
15
16
- var node = new Node ( element ) ,
16
+ let node = new Node ( element ) ,
17
17
current ;
18
18
19
19
if ( head === null ) { //first node on list
@@ -35,7 +35,7 @@ function DoublyLinkedList() {
35
35
//check for out-of-bounds values
36
36
if ( position >= 0 && position <= length ) {
37
37
38
- var node = new Node ( element ) ,
38
+ let node = new Node ( element ) ,
39
39
current = head ,
40
40
previous ,
41
41
index = 0 ;
@@ -84,7 +84,7 @@ function DoublyLinkedList() {
84
84
//check for out-of-bounds values
85
85
if ( position > - 1 && position < length ) {
86
86
87
- var current = head ,
87
+ let current = head ,
88
88
previous ,
89
89
index = 0 ;
90
90
@@ -130,13 +130,13 @@ function DoublyLinkedList() {
130
130
131
131
this . remove = function ( element ) {
132
132
133
- var index = this . indexOf ( element ) ;
133
+ let index = this . indexOf ( element ) ;
134
134
return this . removeAt ( index ) ;
135
135
} ;
136
136
137
137
this . indexOf = function ( element ) {
138
138
139
- var current = head ,
139
+ let current = head ,
140
140
index = - 1 ;
141
141
142
142
//check first item
@@ -175,7 +175,7 @@ function DoublyLinkedList() {
175
175
176
176
this . toString = function ( ) {
177
177
178
- var current = head ,
178
+ let current = head ,
179
179
s = current ? current . element : '' ;
180
180
181
181
while ( current && current . next ) {
@@ -188,7 +188,7 @@ function DoublyLinkedList() {
188
188
189
189
this . inverseToString = function ( ) {
190
190
191
- var current = tail ,
191
+ let current = tail ,
192
192
s = current ? current . element : '' ;
193
193
194
194
while ( current && current . prev ) {
0 commit comments