1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = LinkedList;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function LinkedList() {
|
16 | this.head = null;
|
17 | this.length = 0;
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | LinkedList.prototype.add = function (x) {
|
25 | if (this.head !== null) {
|
26 | this.head.prev = x;
|
27 | x.next = this.head;
|
28 | }
|
29 | this.head = x;
|
30 | ++this.length;
|
31 | };
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | LinkedList.prototype.remove = function (x) {
|
38 |
|
39 | --this.length;
|
40 | if (x === this.head) {
|
41 | this.head = this.head.next;
|
42 | }
|
43 | if (x.next !== null) {
|
44 | x.next.prev = x.prev;
|
45 | x.next = null;
|
46 | }
|
47 | if (x.prev !== null) {
|
48 | x.prev.next = x.next;
|
49 | x.prev = null;
|
50 | }
|
51 | };
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | LinkedList.prototype.isEmpty = function () {
|
57 | return this.length === 0;
|
58 | };
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | LinkedList.prototype.dispose = function () {
|
66 | if (this.isEmpty()) {
|
67 | return Promise.resolve();
|
68 | }
|
69 |
|
70 | var promises = [];
|
71 | var x = this.head;
|
72 | this.head = null;
|
73 | this.length = 0;
|
74 |
|
75 | while (x !== null) {
|
76 | promises.push(x.dispose());
|
77 | x = x.next;
|
78 | }
|
79 |
|
80 | return Promise.all(promises);
|
81 | }; |
\ | No newline at end of file |