forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.js
More file actions
51 lines (35 loc) · 712 Bytes
/
linked_list.js
File metadata and controls
51 lines (35 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class LinkedList {
constructor() {
this._list = [];
}
get list() {
return this._list;
}
set list( val ) {
return true;
}
push( value ) {
const newNode = new Node({
next: null,
previous: null,
value
});
if( this._list.length === 0 ) {
this._list.push( newNode );
return;
}
const oldNode = this._list.pop();
oldNode.next = newNode;
newNode.previous = oldNode;
this._list.push( oldNode );
this._list.push( newNode );
}
remove( node ) {
}
}
class Node {
constructor({ next, previous, value }) {
Object.assign( this, { next, previous, value } );
}
}
module.exports = new LinkedList();