mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 12:54:04 +00:00
docs: Integration tests and documentation for free conversion between data structures.
This commit is contained in:
parent
982152abc0
commit
3dc0454c24
71
README.md
71
README.md
|
@ -296,6 +296,77 @@ graph.addEdge('B', 'D');
|
|||
|
||||
const dijkstraResult = graph.dijkstra('A');
|
||||
Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', 'D']
|
||||
|
||||
|
||||
```
|
||||
|
||||
### Free conversion between data structures.
|
||||
|
||||
```js
|
||||
const orgArr = [6, 1, 2, 7, 5, 3, 4, 9, 8];
|
||||
const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle", "track", "trace", "transmit"];
|
||||
const entries = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
||||
|
||||
const queue = new Queue(orgArr);
|
||||
queue.print();
|
||||
|
||||
const deque = new Deque(orgArr);
|
||||
deque.print();
|
||||
|
||||
const sList = new SinglyLinkedList(orgArr);
|
||||
sList.print();
|
||||
|
||||
const dList = new DoublyLinkedList(orgArr);
|
||||
dList.print();
|
||||
|
||||
const stack = new Stack(orgArr);
|
||||
stack.print();
|
||||
|
||||
const minHeap = new MinHeap(orgArr);
|
||||
minHeap.print();
|
||||
|
||||
const maxPQ = new MaxPriorityQueue(orgArr);
|
||||
maxPQ.print();
|
||||
|
||||
const biTree = new BinaryTree(entries);
|
||||
biTree.print();
|
||||
|
||||
const bst = new BST(entries);
|
||||
bst.print();
|
||||
|
||||
const rbTree = new RedBlackTree(entries);
|
||||
rbTree.print();
|
||||
|
||||
const avl = new AVLTree(entries);
|
||||
avl.print();
|
||||
|
||||
const treeMulti = new TreeMultimap(entries);
|
||||
treeMulti.print();
|
||||
|
||||
const hm = new HashMap(entries);
|
||||
hm.print()
|
||||
const rbTreeH = new RedBlackTree(hm);
|
||||
rbTreeH.print();
|
||||
|
||||
const pq = new MinPriorityQueue(orgArr);
|
||||
pq.print();
|
||||
const bst1 = new BST(pq);
|
||||
bst1.print();
|
||||
|
||||
const dq1 = new Deque(orgArr);
|
||||
dq1.print();
|
||||
const rbTree1 = new RedBlackTree(dq1);
|
||||
rbTree1.print();
|
||||
|
||||
const trie2 = new Trie(orgStrArr);
|
||||
trie2.print();
|
||||
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
|
||||
heap2.print();
|
||||
const dq2 = new Deque(heap2);
|
||||
dq2.print();
|
||||
const entries2 = dq2.map((el, i) => [i, el]);
|
||||
const avl2 = new AVLTree(entries2);
|
||||
avl2.print();
|
||||
```
|
||||
|
||||
## API docs & Examples
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "data-structure-typed",
|
||||
"version": "1.47.6",
|
||||
"version": "1.47.7",
|
||||
"description": "Data Structures of Javascript & TypeScript. Heap, Binary Tree, RedBlack Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack.",
|
||||
"main": "dist/cjs/index.js",
|
||||
"module": "dist/mjs/index.js",
|
||||
|
|
|
@ -215,6 +215,93 @@
|
|||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
try {
|
||||
const {
|
||||
AVLTree,
|
||||
BinaryTree,
|
||||
BST,
|
||||
Deque,
|
||||
DoublyLinkedList,
|
||||
HashMap,
|
||||
Heap,
|
||||
MaxPriorityQueue,
|
||||
MinHeap,
|
||||
MinPriorityQueue,
|
||||
Queue,
|
||||
RedBlackTree,
|
||||
SinglyLinkedList,
|
||||
Stack,
|
||||
TreeMultimap,
|
||||
Trie
|
||||
} = dataStructureTyped;
|
||||
const orgArr = [6, 1, 2, 7, 5, 3, 4, 9, 8];
|
||||
const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle", "track", "trace", "transmit"];
|
||||
const entries = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
||||
|
||||
const queue = new Queue(orgArr);
|
||||
queue.print();
|
||||
|
||||
const deque = new Deque(orgArr);
|
||||
deque.print();
|
||||
|
||||
const sList = new SinglyLinkedList(orgArr);
|
||||
sList.print();
|
||||
|
||||
const dList = new DoublyLinkedList(orgArr);
|
||||
dList.print();
|
||||
|
||||
const stack = new Stack(orgArr);
|
||||
stack.print();
|
||||
|
||||
const minHeap = new MinHeap(orgArr);
|
||||
minHeap.print();
|
||||
|
||||
const maxPQ = new MaxPriorityQueue(orgArr);
|
||||
maxPQ.print();
|
||||
|
||||
const biTree = new BinaryTree(entries);
|
||||
biTree.print();
|
||||
|
||||
const bst = new BST(entries);
|
||||
bst.print();
|
||||
|
||||
const rbTree = new RedBlackTree(entries);
|
||||
rbTree.print();
|
||||
|
||||
const avl = new AVLTree(entries);
|
||||
avl.print();
|
||||
|
||||
const treeMulti = new TreeMultimap(entries);
|
||||
treeMulti.print();
|
||||
|
||||
const hm = new HashMap(entries);
|
||||
hm.print()
|
||||
const rbTreeH = new RedBlackTree(hm);
|
||||
rbTreeH.print();
|
||||
|
||||
const pq = new MinPriorityQueue(orgArr);
|
||||
pq.print();
|
||||
const bst1 = new BST(pq);
|
||||
bst1.print();
|
||||
|
||||
const dq1 = new Deque(orgArr);
|
||||
dq1.print();
|
||||
const rbTree1 = new RedBlackTree(dq1);
|
||||
rbTree1.print();
|
||||
|
||||
const trie2 = new Trie(orgStrArr);
|
||||
trie2.print();
|
||||
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
|
||||
heap2.print();
|
||||
const dq2 = new Deque(heap2);
|
||||
dq2.print();
|
||||
const entries2 = dq2.map((el, i) => [i, el]);
|
||||
const avl2 = new AVLTree(entries2);
|
||||
avl2.print();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue