typescript-ds-lib 0.0.1 → 0.1.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 +32 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/binary-search-tree.d.ts +35 -0
- package/dist/lib/binary-search-tree.js +144 -0
- package/dist/lib/binary-search-tree.js.map +1 -0
- package/dist/lib/deque.d.ts +41 -0
- package/dist/lib/deque.js +65 -0
- package/dist/lib/deque.js.map +1 -0
- package/dist/lib/linked-list.d.ts +43 -0
- package/dist/lib/linked-list.js +172 -0
- package/dist/lib/linked-list.js.map +1 -0
- package/dist/lib/priority-queue.d.ts +32 -0
- package/dist/lib/priority-queue.js +61 -0
- package/dist/lib/priority-queue.js.map +1 -0
- package/dist/lib/queue.d.ts +29 -0
- package/dist/lib/queue.js +47 -0
- package/dist/lib/queue.js.map +1 -0
- package/dist/lib/stack.d.ts +2 -1
- package/dist/lib/stack.js.map +1 -1
- package/dist/tests/binary-search-tree.test.d.ts +1 -0
- package/dist/tests/binary-search-tree.test.js +75 -0
- package/dist/tests/binary-search-tree.test.js.map +1 -0
- package/dist/tests/deque.test.d.ts +1 -0
- package/dist/tests/deque.test.js +78 -0
- package/dist/tests/deque.test.js.map +1 -0
- package/dist/tests/linked-list.test.d.ts +1 -0
- package/dist/tests/linked-list.test.js +101 -0
- package/dist/tests/linked-list.test.js.map +1 -0
- package/dist/tests/priority-queue.test.d.ts +1 -0
- package/dist/tests/priority-queue.test.js +59 -0
- package/dist/tests/priority-queue.test.js.map +1 -0
- package/dist/tests/queue.test.d.ts +1 -0
- package/dist/tests/queue.test.js +48 -0
- package/dist/tests/queue.test.js.map +1 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
# TypeScript Data Structure Library
|
|
2
|
+
[](https://www.npmjs.com/package/typescript-ds-lib)
|
|
3
|
+
|
|
2
4
|
Native TypeScript data structure implementations without external dependencies.
|
|
3
5
|
|
|
6
|
+
- Fast, Light and Tested
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
```
|
|
10
|
+
npm install typescript-ds-lib
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
```typescript
|
|
15
|
+
import { Stack, StackTy } from 'typescript-ds-lib';
|
|
16
|
+
|
|
17
|
+
const stack: StackTy<number> = new Stack<number>();
|
|
18
|
+
|
|
19
|
+
stack.push(1);
|
|
20
|
+
stack.push(2);
|
|
21
|
+
stack.push(3);
|
|
22
|
+
|
|
23
|
+
console.log(stack.top()); // 3
|
|
24
|
+
console.log(stack.pop()); // 3
|
|
25
|
+
console.log(stack.size()); // 2
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Data Structures
|
|
29
|
+
- Stack
|
|
30
|
+
- Queue
|
|
31
|
+
- Priority Queue
|
|
32
|
+
- Linked List
|
|
33
|
+
- Binary Search Tree
|
|
34
|
+
- Deque
|
|
35
|
+
|
|
4
36
|
|
|
5
37
|
## Contributions
|
|
6
38
|
Contributions are welcome and can be made by submitting GitHub pull requests
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { Stack } from './lib/stack';
|
|
3
|
+
export { Queue } from './lib/queue';
|
|
4
|
+
export { PriorityQueue } from './lib/priority-queue';
|
|
5
|
+
export { BinarySearchTree } from './lib/binary-search-tree';
|
|
6
|
+
export { Deque } from './lib/deque';
|
|
7
|
+
export { LinkedList } from './lib/linked-list';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.LinkedList = exports.Deque = exports.BinarySearchTree = exports.PriorityQueue = exports.Queue = exports.Stack = void 0;
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
var stack_1 = require("./lib/stack");
|
|
20
|
+
Object.defineProperty(exports, "Stack", { enumerable: true, get: function () { return stack_1.Stack; } });
|
|
21
|
+
var queue_1 = require("./lib/queue");
|
|
22
|
+
Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return queue_1.Queue; } });
|
|
23
|
+
var priority_queue_1 = require("./lib/priority-queue");
|
|
24
|
+
Object.defineProperty(exports, "PriorityQueue", { enumerable: true, get: function () { return priority_queue_1.PriorityQueue; } });
|
|
25
|
+
var binary_search_tree_1 = require("./lib/binary-search-tree");
|
|
26
|
+
Object.defineProperty(exports, "BinarySearchTree", { enumerable: true, get: function () { return binary_search_tree_1.BinarySearchTree; } });
|
|
27
|
+
var deque_1 = require("./lib/deque");
|
|
28
|
+
Object.defineProperty(exports, "Deque", { enumerable: true, get: function () { return deque_1.Deque; } });
|
|
29
|
+
var linked_list_1 = require("./lib/linked-list");
|
|
30
|
+
Object.defineProperty(exports, "LinkedList", { enumerable: true, get: function () { return linked_list_1.LinkedList; } });
|
|
3
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,qCAAoC;AAA3B,8FAAA,KAAK,OAAA;AACd,qCAAoC;AAA3B,8FAAA,KAAK,OAAA;AACd,uDAAqD;AAA5C,+GAAA,aAAa,OAAA;AACtB,+DAA4D;AAAnD,sHAAA,gBAAgB,OAAA;AACzB,qCAAoC;AAA3B,8FAAA,KAAK,OAAA;AACd,iDAA+C;AAAtC,yGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BinarySearchTreeTy } from '../types';
|
|
2
|
+
export declare class BinarySearchTree<T> implements BinarySearchTreeTy<T> {
|
|
3
|
+
private root;
|
|
4
|
+
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Inserts a value into the BST
|
|
7
|
+
*/
|
|
8
|
+
insert(value: T): void;
|
|
9
|
+
/**
|
|
10
|
+
* Searches for a value in the BST. Returns true if found, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
find(value: T): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the minimum value in the BST, or undefined if tree is empty
|
|
15
|
+
*/
|
|
16
|
+
min(): T | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the maximum value in the BST, or undefined if tree is empty
|
|
19
|
+
*/
|
|
20
|
+
max(): T | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Removes a value from the BST if it exists
|
|
23
|
+
*/
|
|
24
|
+
remove(value: T): void;
|
|
25
|
+
private removeNode;
|
|
26
|
+
private findMin;
|
|
27
|
+
/**
|
|
28
|
+
* Returns true if the BST is empty, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
empty(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Removes all nodes from the BST
|
|
33
|
+
*/
|
|
34
|
+
clear(): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BinarySearchTree = void 0;
|
|
4
|
+
class TreeNode {
|
|
5
|
+
value;
|
|
6
|
+
left;
|
|
7
|
+
right;
|
|
8
|
+
constructor(value) {
|
|
9
|
+
this.value = value;
|
|
10
|
+
this.left = null;
|
|
11
|
+
this.right = null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
class BinarySearchTree {
|
|
15
|
+
root;
|
|
16
|
+
constructor() {
|
|
17
|
+
this.root = null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Inserts a value into the BST
|
|
21
|
+
*/
|
|
22
|
+
insert(value) {
|
|
23
|
+
const newNode = new TreeNode(value);
|
|
24
|
+
if (!this.root) {
|
|
25
|
+
this.root = newNode;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
let current = this.root;
|
|
29
|
+
while (true) {
|
|
30
|
+
if (value < current.value) {
|
|
31
|
+
if (current.left === null) {
|
|
32
|
+
current.left = newNode;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
current = current.left;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (current.right === null) {
|
|
39
|
+
current.right = newNode;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
current = current.right;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Searches for a value in the BST. Returns true if found, false otherwise
|
|
48
|
+
*/
|
|
49
|
+
find(value) {
|
|
50
|
+
let current = this.root;
|
|
51
|
+
while (current !== null) {
|
|
52
|
+
if (value === current.value) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (value < current.value) {
|
|
56
|
+
current = current.left;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
current = current.right;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the minimum value in the BST, or undefined if tree is empty
|
|
66
|
+
*/
|
|
67
|
+
min() {
|
|
68
|
+
if (!this.root)
|
|
69
|
+
return undefined;
|
|
70
|
+
let current = this.root;
|
|
71
|
+
while (current.left !== null) {
|
|
72
|
+
current = current.left;
|
|
73
|
+
}
|
|
74
|
+
return current.value;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns the maximum value in the BST, or undefined if tree is empty
|
|
78
|
+
*/
|
|
79
|
+
max() {
|
|
80
|
+
if (!this.root)
|
|
81
|
+
return undefined;
|
|
82
|
+
let current = this.root;
|
|
83
|
+
while (current.right !== null) {
|
|
84
|
+
current = current.right;
|
|
85
|
+
}
|
|
86
|
+
return current.value;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Removes a value from the BST if it exists
|
|
90
|
+
*/
|
|
91
|
+
remove(value) {
|
|
92
|
+
this.root = this.removeNode(this.root, value);
|
|
93
|
+
}
|
|
94
|
+
removeNode(node, value) {
|
|
95
|
+
if (node === null)
|
|
96
|
+
return null;
|
|
97
|
+
if (value < node.value) {
|
|
98
|
+
node.left = this.removeNode(node.left, value);
|
|
99
|
+
return node;
|
|
100
|
+
}
|
|
101
|
+
else if (value > node.value) {
|
|
102
|
+
node.right = this.removeNode(node.right, value);
|
|
103
|
+
return node;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// Node to delete found
|
|
107
|
+
// Case 1: Leaf node
|
|
108
|
+
if (node.left === null && node.right === null) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
// Case 2: Node with one child
|
|
112
|
+
if (node.left === null)
|
|
113
|
+
return node.right;
|
|
114
|
+
if (node.right === null)
|
|
115
|
+
return node.left;
|
|
116
|
+
// Case 3: Node with two children
|
|
117
|
+
const minNode = this.findMin(node.right);
|
|
118
|
+
node.value = minNode.value;
|
|
119
|
+
node.right = this.removeNode(node.right, minNode.value);
|
|
120
|
+
return node;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
findMin(node) {
|
|
124
|
+
let current = node;
|
|
125
|
+
while (current.left !== null) {
|
|
126
|
+
current = current.left;
|
|
127
|
+
}
|
|
128
|
+
return current;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns true if the BST is empty, false otherwise
|
|
132
|
+
*/
|
|
133
|
+
empty() {
|
|
134
|
+
return this.root === null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Removes all nodes from the BST
|
|
138
|
+
*/
|
|
139
|
+
clear() {
|
|
140
|
+
this.root = null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.BinarySearchTree = BinarySearchTree;
|
|
144
|
+
//# sourceMappingURL=binary-search-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-search-tree.js","sourceRoot":"","sources":["../../lib/binary-search-tree.ts"],"names":[],"mappings":";;;AAGA,MAAM,QAAQ;IACZ,KAAK,CAAI;IACT,IAAI,CAAqB;IACzB,KAAK,CAAqB;IAE1B,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;CACF;AAED,MAAa,gBAAgB;IACnB,IAAI,CAAqB;IAEjC;QACE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAQ;QACb,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,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,IAAI,CAAC,KAAK,KAAK,IAAI;gBAAE,OAAO,IAAI,CAAC,IAAI,CAAC;YAC1C,iCAAiC;YACjC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAEO,OAAO,CAAC,IAAiB;QAC/B,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,OAAO,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAnID,4CAmIC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DequeTy } from '../types';
|
|
2
|
+
export declare class Deque<T> implements DequeTy<T> {
|
|
3
|
+
private items;
|
|
4
|
+
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Adds an element to the front of the deque
|
|
7
|
+
*/
|
|
8
|
+
pushFront(element: T): void;
|
|
9
|
+
/**
|
|
10
|
+
* Adds an element to the back of the deque
|
|
11
|
+
*/
|
|
12
|
+
pushBack(element: T): void;
|
|
13
|
+
/**
|
|
14
|
+
* Removes and returns the front element from the deque, or undefined if deque is empty
|
|
15
|
+
*/
|
|
16
|
+
popFront(): T | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Removes and returns the back element from the deque, or undefined if deque is empty
|
|
19
|
+
*/
|
|
20
|
+
popBack(): T | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the front element without removing it, or undefined if deque is empty
|
|
23
|
+
*/
|
|
24
|
+
front(): T | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the back element without removing it, or undefined if deque is empty
|
|
27
|
+
*/
|
|
28
|
+
back(): T | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Returns true if the deque is empty, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
empty(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the number of elements in the deque
|
|
35
|
+
*/
|
|
36
|
+
size(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Removes all elements from the deque
|
|
39
|
+
*/
|
|
40
|
+
clear(): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Deque = void 0;
|
|
4
|
+
class Deque {
|
|
5
|
+
items;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.items = [];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Adds an element to the front of the deque
|
|
11
|
+
*/
|
|
12
|
+
pushFront(element) {
|
|
13
|
+
this.items.unshift(element);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Adds an element to the back of the deque
|
|
17
|
+
*/
|
|
18
|
+
pushBack(element) {
|
|
19
|
+
this.items.push(element);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Removes and returns the front element from the deque, or undefined if deque is empty
|
|
23
|
+
*/
|
|
24
|
+
popFront() {
|
|
25
|
+
return this.items.shift();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Removes and returns the back element from the deque, or undefined if deque is empty
|
|
29
|
+
*/
|
|
30
|
+
popBack() {
|
|
31
|
+
return this.items.pop();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Returns the front element without removing it, or undefined if deque is empty
|
|
35
|
+
*/
|
|
36
|
+
front() {
|
|
37
|
+
return this.items[0];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the back element without removing it, or undefined if deque is empty
|
|
41
|
+
*/
|
|
42
|
+
back() {
|
|
43
|
+
return this.items[this.items.length - 1];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if the deque is empty, false otherwise
|
|
47
|
+
*/
|
|
48
|
+
empty() {
|
|
49
|
+
return this.items.length === 0;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns the number of elements in the deque
|
|
53
|
+
*/
|
|
54
|
+
size() {
|
|
55
|
+
return this.items.length;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Removes all elements from the deque
|
|
59
|
+
*/
|
|
60
|
+
clear() {
|
|
61
|
+
this.items = [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.Deque = Deque;
|
|
65
|
+
//# sourceMappingURL=deque.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deque.js","sourceRoot":"","sources":["../../lib/deque.ts"],"names":[],"mappings":";;;AAGA,MAAa,KAAK;IACR,KAAK,CAAM;IAEnB;QACE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,OAAU;QAClB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,OAAU;QACjB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF;AArED,sBAqEC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LinkedListTy } from '../types';
|
|
2
|
+
export declare class LinkedList<T> implements LinkedListTy<T> {
|
|
3
|
+
private head;
|
|
4
|
+
private tail;
|
|
5
|
+
private length;
|
|
6
|
+
constructor();
|
|
7
|
+
/**
|
|
8
|
+
* Adds an element to the end of the list
|
|
9
|
+
*/
|
|
10
|
+
pushBack(element: T): void;
|
|
11
|
+
/**
|
|
12
|
+
* Adds an element to the front of the list
|
|
13
|
+
*/
|
|
14
|
+
pushFront(element: T): void;
|
|
15
|
+
/**
|
|
16
|
+
* Inserts an element at the specified position. Returns true if successful, false if position is invalid
|
|
17
|
+
*/
|
|
18
|
+
insert(element: T, position: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Removes the first element that satisfies the predicate. Returns true if an element was removed, false otherwise.
|
|
21
|
+
*/
|
|
22
|
+
removeIf(condition: (element: T) => boolean): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Removes and returns the element at the specified position. Returns undefined if position is invalid
|
|
25
|
+
*/
|
|
26
|
+
removeAt(position: number): T | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the element at the specified position without removing it. Returns undefined if position is invalid
|
|
29
|
+
*/
|
|
30
|
+
get(position: number): T | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Returns true if the list is empty, false otherwise
|
|
33
|
+
*/
|
|
34
|
+
empty(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the number of elements in the list
|
|
37
|
+
*/
|
|
38
|
+
size(): number;
|
|
39
|
+
/**
|
|
40
|
+
* Removes all elements from the list
|
|
41
|
+
*/
|
|
42
|
+
clear(): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinkedList = void 0;
|
|
4
|
+
class Node {
|
|
5
|
+
value;
|
|
6
|
+
next;
|
|
7
|
+
constructor(value) {
|
|
8
|
+
this.value = value;
|
|
9
|
+
this.next = null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class LinkedList {
|
|
13
|
+
head;
|
|
14
|
+
tail;
|
|
15
|
+
length;
|
|
16
|
+
constructor() {
|
|
17
|
+
this.head = null;
|
|
18
|
+
this.tail = null;
|
|
19
|
+
this.length = 0;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Adds an element to the end of the list
|
|
23
|
+
*/
|
|
24
|
+
pushBack(element) {
|
|
25
|
+
const newNode = new Node(element);
|
|
26
|
+
if (!this.head) {
|
|
27
|
+
this.head = newNode;
|
|
28
|
+
this.tail = newNode;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.tail.next = newNode;
|
|
32
|
+
this.tail = newNode;
|
|
33
|
+
}
|
|
34
|
+
this.length++;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Adds an element to the front of the list
|
|
38
|
+
*/
|
|
39
|
+
pushFront(element) {
|
|
40
|
+
const newNode = new Node(element);
|
|
41
|
+
if (!this.head) {
|
|
42
|
+
this.head = newNode;
|
|
43
|
+
this.tail = newNode;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
newNode.next = this.head;
|
|
47
|
+
this.head = newNode;
|
|
48
|
+
}
|
|
49
|
+
this.length++;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Inserts an element at the specified position. Returns true if successful, false if position is invalid
|
|
53
|
+
*/
|
|
54
|
+
insert(element, position) {
|
|
55
|
+
if (position < 0 || position > this.length) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (position === 0) {
|
|
59
|
+
this.pushFront(element);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
if (position === this.length) {
|
|
63
|
+
this.pushBack(element);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
const newNode = new Node(element);
|
|
67
|
+
let current = this.head;
|
|
68
|
+
let prev = null;
|
|
69
|
+
let index = 0;
|
|
70
|
+
while (index < position) {
|
|
71
|
+
prev = current;
|
|
72
|
+
current = current.next;
|
|
73
|
+
index++;
|
|
74
|
+
}
|
|
75
|
+
prev.next = newNode;
|
|
76
|
+
newNode.next = current;
|
|
77
|
+
this.length++;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Removes the first element that satisfies the predicate. Returns true if an element was removed, false otherwise.
|
|
82
|
+
*/
|
|
83
|
+
removeIf(condition) {
|
|
84
|
+
let current = this.head;
|
|
85
|
+
let prev = null;
|
|
86
|
+
while (current !== null) {
|
|
87
|
+
if (condition(current.value)) {
|
|
88
|
+
if (prev === null) {
|
|
89
|
+
this.head = current.next;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
prev.next = current.next;
|
|
93
|
+
}
|
|
94
|
+
if (current === this.tail) {
|
|
95
|
+
this.tail = prev;
|
|
96
|
+
}
|
|
97
|
+
this.length--;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
prev = current;
|
|
101
|
+
current = current.next;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Removes and returns the element at the specified position. Returns undefined if position is invalid
|
|
107
|
+
*/
|
|
108
|
+
removeAt(position) {
|
|
109
|
+
if (position < 0 || position >= this.length) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
let current = this.head;
|
|
113
|
+
if (position === 0) {
|
|
114
|
+
this.head = current.next;
|
|
115
|
+
if (this.length === 1) {
|
|
116
|
+
this.tail = null;
|
|
117
|
+
}
|
|
118
|
+
this.length--;
|
|
119
|
+
return current.value;
|
|
120
|
+
}
|
|
121
|
+
let prev = null;
|
|
122
|
+
let index = 0;
|
|
123
|
+
while (index < position) {
|
|
124
|
+
prev = current;
|
|
125
|
+
current = current.next;
|
|
126
|
+
index++;
|
|
127
|
+
}
|
|
128
|
+
prev.next = current.next;
|
|
129
|
+
if (position === this.length - 1) {
|
|
130
|
+
this.tail = prev;
|
|
131
|
+
}
|
|
132
|
+
this.length--;
|
|
133
|
+
return current.value;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns the element at the specified position without removing it. Returns undefined if position is invalid
|
|
137
|
+
*/
|
|
138
|
+
get(position) {
|
|
139
|
+
if (position < 0 || position >= this.length) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
let current = this.head;
|
|
143
|
+
let index = 0;
|
|
144
|
+
while (index < position) {
|
|
145
|
+
current = current.next;
|
|
146
|
+
index++;
|
|
147
|
+
}
|
|
148
|
+
return current.value;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns true if the list is empty, false otherwise
|
|
152
|
+
*/
|
|
153
|
+
empty() {
|
|
154
|
+
return this.length === 0;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Returns the number of elements in the list
|
|
158
|
+
*/
|
|
159
|
+
size() {
|
|
160
|
+
return this.length;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Removes all elements from the list
|
|
164
|
+
*/
|
|
165
|
+
clear() {
|
|
166
|
+
this.head = null;
|
|
167
|
+
this.tail = null;
|
|
168
|
+
this.length = 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.LinkedList = LinkedList;
|
|
172
|
+
//# sourceMappingURL=linked-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linked-list.js","sourceRoot":"","sources":["../../lib/linked-list.ts"],"names":[],"mappings":";;;AAEA,MAAM,IAAI;IACR,KAAK,CAAI;IACT,IAAI,CAAiB;IAErB,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,MAAa,UAAU;IACb,IAAI,CAAiB;IACrB,IAAI,CAAiB;IACrB,MAAM,CAAS;IAEvB;QACE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,OAAU;QACjB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;YACpB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YAC1B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,OAAU;QAClB,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,GAAG,OAAO,C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
|
+
private items;
|
|
4
|
+
constructor();
|
|
5
|
+
/**
|
|
6
|
+
* Adds an element with a priority to the queue.
|
|
7
|
+
* Lower priority numbers have higher precedence.
|
|
8
|
+
*/
|
|
9
|
+
push(element: T, priority: number): void;
|
|
10
|
+
/**
|
|
11
|
+
* Removes and returns the highest priority element from the queue,
|
|
12
|
+
* or undefined if queue is empty.
|
|
13
|
+
*/
|
|
14
|
+
pop(): T | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the highest priority element without removing it,
|
|
17
|
+
* or undefined if queue is empty.
|
|
18
|
+
*/
|
|
19
|
+
front(): T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the queue is empty. Returns true if empty, false otherwise.
|
|
22
|
+
*/
|
|
23
|
+
empty(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the number of elements in the queue.
|
|
26
|
+
*/
|
|
27
|
+
size(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Removes all elements from the queue.
|
|
30
|
+
*/
|
|
31
|
+
clear(): void;
|
|
32
|
+
}
|