4
4
* sake of simplicity.
5
5
*/
6
6
7
- var DoublyLinkedList = function ( ) {
7
+ export function DoublyLinkedList ( ) {
8
8
this . front = new Node ( null , null , null ) ;
9
9
this . back = new Node ( this . front , null , null ) ;
10
10
this . front . next = this . back ;
11
11
this . length = 0 ;
12
- } ;
12
+ }
13
13
14
- var Node = function ( prev , next , value ) {
14
+ export function Node ( prev , next , value ) {
15
15
this . prev = prev ;
16
16
this . next = next ;
17
17
this . value = value ;
18
- } ;
18
+ }
19
19
20
- var Iterator = function ( front , back , current ) {
20
+ export function Iterator ( front , back , current ) {
21
21
this . front = front ;
22
22
this . back = back ;
23
23
this . current = current ;
24
- } ;
24
+ }
25
25
26
- var ReverseIterator = function ( front , back , current ) {
26
+ export function ReverseIterator ( front , back , current ) {
27
27
this . front = front ;
28
28
this . back = back ;
29
29
this . current = current ;
30
- } ;
30
+ }
31
31
32
32
DoublyLinkedList . prototype . insertAfter = function ( iterator , value ) {
33
33
var node , prev ;
@@ -40,7 +40,7 @@ DoublyLinkedList.prototype.insertAfter = function(iterator, value){
40
40
41
41
++ this . length ;
42
42
return this . iterator ( node ) ;
43
- } ;
43
+ }
44
44
45
45
DoublyLinkedList . prototype . insertBefore = function ( iterator , value ) {
46
46
var node , next ;
@@ -53,15 +53,15 @@ DoublyLinkedList.prototype.insertBefore = function(iterator, value){
53
53
54
54
++ this . length ;
55
55
return this . iterator ( node ) ;
56
- } ;
56
+ }
57
57
58
58
DoublyLinkedList . prototype . unshift = function ( value ) {
59
59
return this . insertAfter ( this . begin ( ) , value ) ;
60
- } ;
60
+ }
61
61
62
62
DoublyLinkedList . prototype . push = function ( value ) {
63
63
return this . insertBefore ( this . end ( ) , value ) ;
64
- } ;
64
+ }
65
65
66
66
DoublyLinkedList . prototype . erase = function ( iterator ) {
67
67
var node = iterator . current ;
@@ -71,7 +71,7 @@ DoublyLinkedList.prototype.erase = function(iterator){
71
71
72
72
-- this . length ;
73
73
return this . iterator ( node . next ) ;
74
- } ;
74
+ }
75
75
76
76
DoublyLinkedList . prototype . rerase = function ( iterator ) {
77
77
var node = iterator . current ;
@@ -81,7 +81,7 @@ DoublyLinkedList.prototype.rerase = function(iterator){
81
81
82
82
-- this . length ;
83
83
return this . iterator ( node . prev ) ;
84
- } ;
84
+ }
85
85
86
86
DoublyLinkedList . prototype . eraserange = function ( first , last ) {
87
87
var firstnode , lastnode , it ;
@@ -98,7 +98,7 @@ DoublyLinkedList.prototype.eraserange = function(first, last){
98
98
it . next ( ) ;
99
99
}
100
100
return last . copy ( ) ;
101
- } ;
101
+ }
102
102
103
103
DoublyLinkedList . prototype . reraserange = function ( first , last ) {
104
104
var firstnode , lastnode , it ;
@@ -115,7 +115,7 @@ DoublyLinkedList.prototype.reraserange = function(first, last){
115
115
it . next ( ) ;
116
116
}
117
117
return last . copy ( ) ;
118
- } ;
118
+ }
119
119
120
120
DoublyLinkedList . prototype . shift = function ( ) {
121
121
@@ -130,7 +130,7 @@ DoublyLinkedList.prototype.shift = function ( ) {
130
130
131
131
return node . value ;
132
132
133
- } ;
133
+ }
134
134
135
135
DoublyLinkedList . prototype . pop = function ( ) {
136
136
@@ -145,46 +145,46 @@ DoublyLinkedList.prototype.pop = function ( ) {
145
145
146
146
return node . value ;
147
147
148
- } ;
148
+ }
149
149
150
150
DoublyLinkedList . prototype . clear = function ( ) {
151
151
this . front . next = this . back ;
152
152
this . back . prev = this . front ;
153
153
this . length = 0 ;
154
154
return this ;
155
- } ;
155
+ }
156
156
157
157
DoublyLinkedList . prototype . iterator = function ( node ) {
158
158
return new Iterator ( this . front , this . back , node ) ;
159
- } ;
159
+ }
160
160
161
161
DoublyLinkedList . prototype . riterator = function ( node ) {
162
162
return new ReverseIterator ( this . front , this . back , node ) ;
163
- } ;
163
+ }
164
164
165
165
DoublyLinkedList . prototype . begin = function ( ) {
166
166
return this . iterator ( this . front ) ;
167
- } ;
167
+ }
168
168
169
169
DoublyLinkedList . prototype . end = function ( ) {
170
170
return this . iterator ( this . back ) ;
171
- } ;
171
+ }
172
172
173
173
DoublyLinkedList . prototype . rbegin = function ( ) {
174
174
return this . riterator ( this . back ) ;
175
- } ;
175
+ }
176
176
177
177
DoublyLinkedList . prototype . rend = function ( ) {
178
178
return this . riterator ( this . front ) ;
179
- } ;
179
+ }
180
180
181
181
Iterator . prototype . copy = function ( ) {
182
182
return new Iterator ( this . front , this . back , this . current ) ;
183
- } ;
183
+ }
184
184
185
185
ReverseIterator . prototype . copy = function ( ) {
186
186
return new ReverseIterator ( this . front , this . back , this . current ) ;
187
- } ;
187
+ }
188
188
189
189
Iterator . prototype . next =
190
190
ReverseIterator . prototype . prev = function ( ) {
@@ -193,7 +193,7 @@ ReverseIterator.prototype.prev = function ( ) {
193
193
194
194
return c === this . back ? { done : true } : { value : c . value , done : false } ;
195
195
196
- } ;
196
+ }
197
197
198
198
Iterator . prototype . prev =
199
199
ReverseIterator . prototype . next = function ( ) {
@@ -202,12 +202,11 @@ ReverseIterator.prototype.next = function ( ) {
202
202
203
203
return c === this . front ? { done : true } : { value : c . value , done : false } ;
204
204
205
- } ;
205
+ }
206
206
207
207
DoublyLinkedList . prototype [ Symbol . iterator ] = DoublyLinkedList . prototype . begin ;
208
208
DoublyLinkedList . Node = Node ;
209
209
DoublyLinkedList . Iterator = Iterator ;
210
210
DoublyLinkedList . ReverseIterator = ReverseIterator ;
211
211
212
212
213
- exports . DoublyLinkedList = DoublyLinkedList ;
0 commit comments