data-structure-typed 1.12.11 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +278 -179
- package/dist/data-structures/binary-tree/avl-tree.d.ts +14 -5
- package/dist/data-structures/binary-tree/avl-tree.js +15 -6
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +11 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +11 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +72 -18
- package/dist/data-structures/binary-tree/binary-tree.js +139 -62
- package/dist/data-structures/binary-tree/bst.d.ts +92 -5
- package/dist/data-structures/binary-tree/bst.js +89 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +70 -2
- package/dist/data-structures/binary-tree/segment-tree.js +86 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +34 -3
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -4
- package/dist/data-structures/graph/abstract-graph.d.ts +45 -5
- package/dist/data-structures/graph/abstract-graph.js +59 -11
- package/dist/data-structures/graph/directed-graph.d.ts +26 -4
- package/dist/data-structures/graph/directed-graph.js +38 -39
- package/dist/data-structures/graph/undirected-graph.d.ts +23 -0
- package/dist/data-structures/graph/undirected-graph.js +41 -3
- package/dist/data-structures/hash/coordinate-map.d.ts +12 -3
- package/dist/data-structures/hash/coordinate-map.js +21 -2
- package/dist/data-structures/hash/coordinate-set.d.ts +12 -3
- package/dist/data-structures/hash/coordinate-set.js +21 -2
- package/dist/data-structures/heap/heap.d.ts +25 -6
- package/dist/data-structures/heap/heap.js +46 -8
- package/dist/data-structures/heap/max-heap.d.ts +5 -2
- package/dist/data-structures/heap/max-heap.js +5 -2
- package/dist/data-structures/heap/min-heap.d.ts +5 -2
- package/dist/data-structures/heap/min-heap.js +5 -2
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +32 -9
- package/dist/data-structures/linked-list/doubly-linked-list.js +75 -8
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +267 -330
- package/dist/data-structures/linked-list/singly-linked-list.js +263 -275
- package/dist/data-structures/matrix/matrix.d.ts +5 -2
- package/dist/data-structures/matrix/matrix.js +5 -2
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -2
- package/dist/data-structures/matrix/matrix2d.js +5 -2
- package/dist/data-structures/matrix/navigator.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.js +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +14 -5
- package/dist/data-structures/priority-queue/priority-queue.js +20 -4
- package/dist/data-structures/queue/deque.d.ts +30 -16
- package/dist/data-structures/queue/deque.js +62 -12
- package/dist/data-structures/queue/queue.d.ts +4 -4
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/stack/stack.js +1 -1
- package/dist/data-structures/trie/trie.d.ts +6 -3
- package/dist/data-structures/trie/trie.js +7 -4
- package/dist/data-structures/types/abstract-graph.d.ts +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/utils.d.ts +8 -10
- package/dist/utils/types/utils.js +0 -1
- package/dist/utils/utils.d.ts +18 -8
- package/dist/utils/utils.js +93 -47
- package/package.json +2 -2
- package/src/data-structures/binary-tree/aa-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +84 -14
- package/src/data-structures/binary-tree/segment-tree.ts +45 -13
- package/src/data-structures/graph/abstract-graph.ts +58 -15
- package/src/data-structures/graph/directed-graph.ts +14 -5
- package/src/data-structures/graph/undirected-graph.ts +23 -6
- package/src/data-structures/hash/coordinate-map.ts +13 -1
- package/src/data-structures/hash/coordinate-set.ts +13 -1
- package/src/data-structures/heap/heap.ts +31 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +68 -11
- package/src/data-structures/linked-list/singly-linked-list.ts +312 -334
- package/src/data-structures/priority-queue/priority-queue.ts +15 -2
- package/src/data-structures/queue/deque.ts +38 -8
- package/src/data-structures/types/abstract-graph.ts +3 -3
- package/tests/unit/data-structures/graph/directed-graph.test.ts +431 -8
- package/dist/utils/trampoline.d.ts +0 -14
- package/dist/utils/trampoline.js +0 -130
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
export declare class CoordinateMap<V> extends Map<any, V> {
|
|
6
|
-
|
|
9
|
+
protected _joint: string;
|
|
10
|
+
get joint(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
13
|
+
*/
|
|
14
|
+
getJoint(): string;
|
|
15
|
+
protected set joint(v: string);
|
|
7
16
|
constructor(joint?: string);
|
|
8
17
|
/**
|
|
9
18
|
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|
|
@@ -17,8 +17,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.CoordinateMap = void 0;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* data-structure-typed
|
|
21
|
+
*
|
|
22
|
+
* @author Tyler Zeng
|
|
23
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
|
+
* @license MIT License
|
|
22
25
|
*/
|
|
23
26
|
var CoordinateMap = /** @class */ (function (_super) {
|
|
24
27
|
__extends(CoordinateMap, _super);
|
|
@@ -29,6 +32,22 @@ var CoordinateMap = /** @class */ (function (_super) {
|
|
|
29
32
|
_this._joint = joint;
|
|
30
33
|
return _this;
|
|
31
34
|
}
|
|
35
|
+
Object.defineProperty(CoordinateMap.prototype, "joint", {
|
|
36
|
+
get: function () {
|
|
37
|
+
return this._joint;
|
|
38
|
+
},
|
|
39
|
+
set: function (v) {
|
|
40
|
+
this._joint = v;
|
|
41
|
+
},
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
47
|
+
*/
|
|
48
|
+
CoordinateMap.prototype.getJoint = function () {
|
|
49
|
+
return this._joint;
|
|
50
|
+
};
|
|
32
51
|
/**
|
|
33
52
|
* The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
|
|
34
53
|
* key array with a specified delimiter.
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
export declare class CoordinateSet extends Set {
|
|
6
|
-
|
|
9
|
+
protected _joint: string;
|
|
10
|
+
get joint(): string;
|
|
11
|
+
/**
|
|
12
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
13
|
+
*/
|
|
14
|
+
getJoint(): string;
|
|
15
|
+
protected set joint(v: string);
|
|
7
16
|
constructor(joint?: string);
|
|
8
17
|
/**
|
|
9
18
|
* The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
|
|
@@ -17,8 +17,11 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.CoordinateSet = void 0;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* data-structure-typed
|
|
21
|
+
*
|
|
22
|
+
* @author Tyler Zeng
|
|
23
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
24
|
+
* @license MIT License
|
|
22
25
|
*/
|
|
23
26
|
var CoordinateSet = /** @class */ (function (_super) {
|
|
24
27
|
__extends(CoordinateSet, _super);
|
|
@@ -29,6 +32,22 @@ var CoordinateSet = /** @class */ (function (_super) {
|
|
|
29
32
|
_this._joint = joint;
|
|
30
33
|
return _this;
|
|
31
34
|
}
|
|
35
|
+
Object.defineProperty(CoordinateSet.prototype, "joint", {
|
|
36
|
+
get: function () {
|
|
37
|
+
return this._joint;
|
|
38
|
+
},
|
|
39
|
+
set: function (v) {
|
|
40
|
+
this._joint = v;
|
|
41
|
+
},
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
47
|
+
*/
|
|
48
|
+
CoordinateSet.prototype.getJoint = function () {
|
|
49
|
+
return this._joint;
|
|
50
|
+
};
|
|
32
51
|
/**
|
|
33
52
|
* The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
|
|
34
53
|
* joining its elements with a specified separator.
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
import { PriorityQueue } from '../priority-queue';
|
|
6
9
|
import type { HeapItem, HeapOptions } from '../types';
|
|
7
10
|
export declare abstract class Heap<T> {
|
|
8
11
|
protected abstract _pq: PriorityQueue<HeapItem<T>>;
|
|
12
|
+
get pq(): PriorityQueue<HeapItem<T>>;
|
|
13
|
+
/**
|
|
14
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
15
|
+
*/
|
|
16
|
+
getPq(): PriorityQueue<HeapItem<T>>;
|
|
17
|
+
protected set pq(v: PriorityQueue<HeapItem<T>>);
|
|
9
18
|
protected _priorityCb: (element: T) => number;
|
|
19
|
+
get priorityCb(): (element: T) => number;
|
|
20
|
+
/**
|
|
21
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
22
|
+
*/
|
|
23
|
+
getPriorityCb(): (element: T) => number;
|
|
24
|
+
protected set priorityCb(v: (element: T) => number);
|
|
10
25
|
/**
|
|
11
26
|
* The function is a constructor for a class that initializes a priority callback function based on the
|
|
12
27
|
* options provided.
|
|
@@ -18,6 +33,10 @@ export declare abstract class Heap<T> {
|
|
|
18
33
|
* @returns The size of the priority queue.
|
|
19
34
|
*/
|
|
20
35
|
get size(): number;
|
|
36
|
+
/**
|
|
37
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
38
|
+
*/
|
|
39
|
+
getSize(): number;
|
|
21
40
|
/**
|
|
22
41
|
* The function checks if a priority queue is empty.
|
|
23
42
|
* @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
|
|
@@ -34,16 +53,16 @@ export declare abstract class Heap<T> {
|
|
|
34
53
|
*/
|
|
35
54
|
peekLast(): HeapItem<T> | null;
|
|
36
55
|
/**
|
|
37
|
-
* The `
|
|
56
|
+
* The `add` function adds an element to a priority queue with an optional priority value.
|
|
38
57
|
* @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
|
|
39
58
|
* type.
|
|
40
59
|
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
41
|
-
* element being
|
|
60
|
+
* element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
|
|
42
61
|
* the value of `element`. If the `element` parameter is not a number, then the
|
|
43
|
-
* @returns The `
|
|
62
|
+
* @returns The `add` method returns the instance of the `Heap` class.
|
|
44
63
|
* @throws {Error} if priority is not a valid number
|
|
45
64
|
*/
|
|
46
|
-
|
|
65
|
+
add(element: T, priority?: number): Heap<T>;
|
|
47
66
|
/**
|
|
48
67
|
* The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an element with the highest priority in the queue
|
|
49
68
|
* @returns either a HeapItem<T> object or null.
|
|
@@ -19,6 +19,38 @@ var Heap = /** @class */ (function () {
|
|
|
19
19
|
this._priorityCb = function (el) { return +el; };
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
Object.defineProperty(Heap.prototype, "pq", {
|
|
23
|
+
get: function () {
|
|
24
|
+
return this._pq;
|
|
25
|
+
},
|
|
26
|
+
set: function (v) {
|
|
27
|
+
this._pq = v;
|
|
28
|
+
},
|
|
29
|
+
enumerable: false,
|
|
30
|
+
configurable: true
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
34
|
+
*/
|
|
35
|
+
Heap.prototype.getPq = function () {
|
|
36
|
+
return this._pq;
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(Heap.prototype, "priorityCb", {
|
|
39
|
+
get: function () {
|
|
40
|
+
return this._priorityCb;
|
|
41
|
+
},
|
|
42
|
+
set: function (v) {
|
|
43
|
+
this._priorityCb = v;
|
|
44
|
+
},
|
|
45
|
+
enumerable: false,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
50
|
+
*/
|
|
51
|
+
Heap.prototype.getPriorityCb = function () {
|
|
52
|
+
return this._priorityCb;
|
|
53
|
+
};
|
|
22
54
|
Object.defineProperty(Heap.prototype, "size", {
|
|
23
55
|
/**
|
|
24
56
|
* The function returns the size of a priority queue.
|
|
@@ -30,6 +62,12 @@ var Heap = /** @class */ (function () {
|
|
|
30
62
|
enumerable: false,
|
|
31
63
|
configurable: true
|
|
32
64
|
});
|
|
65
|
+
/**
|
|
66
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
67
|
+
*/
|
|
68
|
+
Heap.prototype.getSize = function () {
|
|
69
|
+
return this._pq.size;
|
|
70
|
+
};
|
|
33
71
|
/**
|
|
34
72
|
* The function checks if a priority queue is empty.
|
|
35
73
|
* @returns {boolean} A boolean value indicating whether the size of the priority queue is less than 1.
|
|
@@ -52,33 +90,33 @@ var Heap = /** @class */ (function () {
|
|
|
52
90
|
return this._pq.leaf();
|
|
53
91
|
};
|
|
54
92
|
/**
|
|
55
|
-
* The `
|
|
93
|
+
* The `add` function adds an element to a priority queue with an optional priority value.
|
|
56
94
|
* @param {T} element - The `element` parameter represents the value that you want to add to the heap. It can be of any
|
|
57
95
|
* type.
|
|
58
96
|
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
|
|
59
|
-
* element being
|
|
97
|
+
* element being added to the heap. If the `element` parameter is a number, then the `priority` parameter is set to
|
|
60
98
|
* the value of `element`. If the `element` parameter is not a number, then the
|
|
61
|
-
* @returns The `
|
|
99
|
+
* @returns The `add` method returns the instance of the `Heap` class.
|
|
62
100
|
* @throws {Error} if priority is not a valid number
|
|
63
101
|
*/
|
|
64
|
-
Heap.prototype.
|
|
102
|
+
Heap.prototype.add = function (element, priority) {
|
|
65
103
|
if (typeof element === 'number') {
|
|
66
104
|
priority = element;
|
|
67
105
|
}
|
|
68
106
|
else {
|
|
69
107
|
if (priority === undefined) {
|
|
70
|
-
throw new Error('.
|
|
108
|
+
throw new Error('.add expects a numeric priority');
|
|
71
109
|
}
|
|
72
110
|
}
|
|
73
111
|
if (priority && Number.isNaN(+priority)) {
|
|
74
|
-
throw new Error('.
|
|
112
|
+
throw new Error('.add expects a numeric priority');
|
|
75
113
|
}
|
|
76
114
|
if (Number.isNaN(+priority) && Number.isNaN(this._priorityCb(element))) {
|
|
77
|
-
throw new Error('.
|
|
115
|
+
throw new Error('.add expects a numeric priority '
|
|
78
116
|
+ 'or a constructor callback that returns a number');
|
|
79
117
|
}
|
|
80
118
|
var _priority = !Number.isNaN(+priority) ? priority : this._priorityCb(element);
|
|
81
|
-
this._pq.
|
|
119
|
+
this._pq.add({ priority: _priority, element: element });
|
|
82
120
|
return this;
|
|
83
121
|
};
|
|
84
122
|
/**
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
import { Heap } from './heap';
|
|
6
9
|
import { PriorityQueue } from '../priority-queue';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
5
8
|
*/
|
|
6
9
|
var __extends = (this && this.__extends) || (function () {
|
|
7
10
|
var extendStatics = function (d, b) {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
import { Heap } from './heap';
|
|
6
9
|
import { PriorityQueue } from '../priority-queue';
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
5
8
|
*/
|
|
6
9
|
var __extends = (this && this.__extends) || (function () {
|
|
7
10
|
var extendStatics = function (d, b) {
|
|
@@ -1,29 +1,52 @@
|
|
|
1
1
|
export declare class DoublyLinkedListNode<T> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
protected _val: T;
|
|
3
|
+
get val(): T;
|
|
4
|
+
set val(v: T);
|
|
5
|
+
protected _next: DoublyLinkedListNode<T> | null;
|
|
6
|
+
get next(): DoublyLinkedListNode<T> | null;
|
|
7
|
+
set next(v: DoublyLinkedListNode<T> | null);
|
|
8
|
+
protected _prev: DoublyLinkedListNode<T> | null;
|
|
9
|
+
get prev(): DoublyLinkedListNode<T> | null;
|
|
10
|
+
set prev(v: DoublyLinkedListNode<T> | null);
|
|
5
11
|
constructor(nodeValue: T);
|
|
6
12
|
}
|
|
7
13
|
export declare class DoublyLinkedList<T> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
protected _first: DoublyLinkedListNode<T> | null;
|
|
15
|
+
get first(): DoublyLinkedListNode<T> | null;
|
|
16
|
+
/**
|
|
17
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
18
|
+
*/
|
|
19
|
+
getFirst(): DoublyLinkedListNode<T> | null;
|
|
20
|
+
protected set first(v: DoublyLinkedListNode<T> | null);
|
|
21
|
+
protected _last: DoublyLinkedListNode<T> | null;
|
|
22
|
+
get last(): DoublyLinkedListNode<T> | null;
|
|
23
|
+
/**
|
|
24
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
25
|
+
*/
|
|
26
|
+
getLast(): DoublyLinkedListNode<T> | null;
|
|
27
|
+
protected set last(v: DoublyLinkedListNode<T> | null);
|
|
28
|
+
protected _size: number;
|
|
11
29
|
get size(): number;
|
|
12
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
32
|
+
*/
|
|
33
|
+
getSize(): number;
|
|
34
|
+
protected set size(v: number);
|
|
35
|
+
constructor();
|
|
13
36
|
/**
|
|
14
37
|
* The function adds a new node with a given value to the beginning of a doubly linked list.
|
|
15
38
|
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of
|
|
16
39
|
* the doubly linked list.
|
|
17
40
|
* @returns A boolean value is being returned.
|
|
18
41
|
*/
|
|
19
|
-
|
|
42
|
+
addFirst(val: T): boolean;
|
|
20
43
|
/**
|
|
21
44
|
* The function adds a new node with a given value to the end of a doubly linked list.
|
|
22
45
|
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the end of the
|
|
23
46
|
* doubly linked list.
|
|
24
47
|
* @returns a boolean value, which is always true.
|
|
25
48
|
*/
|
|
26
|
-
|
|
49
|
+
addLast(val: T): boolean;
|
|
27
50
|
peekFirst(): T | null;
|
|
28
51
|
peekFirst(by: 'val'): T | null;
|
|
29
52
|
peekFirst(by: 'node'): DoublyLinkedListNode<T> | null;
|
|
@@ -3,10 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
|
|
4
4
|
var DoublyLinkedListNode = /** @class */ (function () {
|
|
5
5
|
function DoublyLinkedListNode(nodeValue) {
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
6
|
+
this._val = nodeValue;
|
|
7
|
+
this._next = null;
|
|
8
|
+
this._prev = null;
|
|
9
9
|
}
|
|
10
|
+
Object.defineProperty(DoublyLinkedListNode.prototype, "val", {
|
|
11
|
+
get: function () {
|
|
12
|
+
return this._val;
|
|
13
|
+
},
|
|
14
|
+
set: function (v) {
|
|
15
|
+
this._val = v;
|
|
16
|
+
},
|
|
17
|
+
enumerable: false,
|
|
18
|
+
configurable: true
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(DoublyLinkedListNode.prototype, "next", {
|
|
21
|
+
get: function () {
|
|
22
|
+
return this._next;
|
|
23
|
+
},
|
|
24
|
+
set: function (v) {
|
|
25
|
+
this._next = v;
|
|
26
|
+
},
|
|
27
|
+
enumerable: false,
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(DoublyLinkedListNode.prototype, "prev", {
|
|
31
|
+
get: function () {
|
|
32
|
+
return this._prev;
|
|
33
|
+
},
|
|
34
|
+
set: function (v) {
|
|
35
|
+
this._prev = v;
|
|
36
|
+
},
|
|
37
|
+
enumerable: false,
|
|
38
|
+
configurable: true
|
|
39
|
+
});
|
|
10
40
|
return DoublyLinkedListNode;
|
|
11
41
|
}());
|
|
12
42
|
exports.DoublyLinkedListNode = DoublyLinkedListNode;
|
|
@@ -15,8 +45,39 @@ var DoublyLinkedList = /** @class */ (function () {
|
|
|
15
45
|
this._first = null;
|
|
16
46
|
this._last = null;
|
|
17
47
|
this._size = 0;
|
|
18
|
-
// --- end extra methods ---
|
|
19
48
|
}
|
|
49
|
+
Object.defineProperty(DoublyLinkedList.prototype, "first", {
|
|
50
|
+
get: function () {
|
|
51
|
+
return this._first;
|
|
52
|
+
},
|
|
53
|
+
set: function (v) {
|
|
54
|
+
this._first = v;
|
|
55
|
+
},
|
|
56
|
+
enumerable: false,
|
|
57
|
+
configurable: true
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
61
|
+
*/
|
|
62
|
+
DoublyLinkedList.prototype.getFirst = function () {
|
|
63
|
+
return this._first;
|
|
64
|
+
};
|
|
65
|
+
Object.defineProperty(DoublyLinkedList.prototype, "last", {
|
|
66
|
+
get: function () {
|
|
67
|
+
return this._last;
|
|
68
|
+
},
|
|
69
|
+
set: function (v) {
|
|
70
|
+
this._last = v;
|
|
71
|
+
},
|
|
72
|
+
enumerable: false,
|
|
73
|
+
configurable: true
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
77
|
+
*/
|
|
78
|
+
DoublyLinkedList.prototype.getLast = function () {
|
|
79
|
+
return this._last;
|
|
80
|
+
};
|
|
20
81
|
Object.defineProperty(DoublyLinkedList.prototype, "size", {
|
|
21
82
|
get: function () {
|
|
22
83
|
return this._size;
|
|
@@ -27,13 +88,19 @@ var DoublyLinkedList = /** @class */ (function () {
|
|
|
27
88
|
enumerable: false,
|
|
28
89
|
configurable: true
|
|
29
90
|
});
|
|
91
|
+
/**
|
|
92
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
93
|
+
*/
|
|
94
|
+
DoublyLinkedList.prototype.getSize = function () {
|
|
95
|
+
return this._size;
|
|
96
|
+
};
|
|
30
97
|
/**
|
|
31
98
|
* The function adds a new node with a given value to the beginning of a doubly linked list.
|
|
32
99
|
* @param {T} val - The `val` parameter represents the value of the element that you want to add to the beginning of
|
|
33
100
|
* the doubly linked list.
|
|
34
101
|
* @returns A boolean value is being returned.
|
|
35
102
|
*/
|
|
36
|
-
DoublyLinkedList.prototype.
|
|
103
|
+
DoublyLinkedList.prototype.addFirst = function (val) {
|
|
37
104
|
var newNode = new DoublyLinkedListNode(val);
|
|
38
105
|
if (this._size === 0) {
|
|
39
106
|
this._first = newNode;
|
|
@@ -54,7 +121,7 @@ var DoublyLinkedList = /** @class */ (function () {
|
|
|
54
121
|
* doubly linked list.
|
|
55
122
|
* @returns a boolean value, which is always true.
|
|
56
123
|
*/
|
|
57
|
-
DoublyLinkedList.prototype.
|
|
124
|
+
DoublyLinkedList.prototype.addLast = function (val) {
|
|
58
125
|
var newNode = new DoublyLinkedListNode(val);
|
|
59
126
|
if (this._size === 0) {
|
|
60
127
|
this._first = newNode;
|
|
@@ -247,9 +314,9 @@ var DoublyLinkedList = /** @class */ (function () {
|
|
|
247
314
|
if (index < 0 || index > this._size)
|
|
248
315
|
return false;
|
|
249
316
|
if (index === 0)
|
|
250
|
-
return !!this.
|
|
317
|
+
return !!this.addFirst(val);
|
|
251
318
|
if (index === this._size)
|
|
252
|
-
return !!this.
|
|
319
|
+
return !!this.addLast(val);
|
|
253
320
|
var newNode = new DoublyLinkedListNode(val);
|
|
254
321
|
var prevNode = this.get(index - 1, 'node');
|
|
255
322
|
var nextNode = prevNode === null || prevNode === void 0 ? void 0 : prevNode.next;
|