mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-14 01:24:03 +00:00
74 lines
1.6 KiB
HTML
74 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang='en'>
|
|
<head>
|
|
<meta charset='UTF-8'>
|
|
<title>CDN Test</title>
|
|
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>
|
|
</head>
|
|
<body>
|
|
<div id='app'>
|
|
<ul class='modules'>
|
|
|
|
</ul>
|
|
</div>
|
|
<script defer>
|
|
const $modules = document.querySelector('.modules');
|
|
|
|
|
|
try {
|
|
const {AVLTree, Queue} = window.dataStructureTyped;
|
|
const avlTree = new AVLTree();
|
|
const $avlTree = document.createElement('li');
|
|
const $avlTreeSpan = document.createElement('span');
|
|
$avlTreeSpan.innerText = 'AVLTree';
|
|
$avlTree.append($avlTreeSpan);
|
|
avlTree.add(1, 1);
|
|
console.log(avlTree.bfs());
|
|
$modules.append($avlTree);
|
|
|
|
|
|
const queue = new Queue();
|
|
for (let i = 0; i < 100000; i++) {
|
|
queue.enqueue(i);
|
|
}
|
|
let last = 0;
|
|
const startTime = performance.now();
|
|
|
|
for (let i = 0; i < 100000; i++) {
|
|
last = queue.dequeue();
|
|
}
|
|
|
|
console.log(performance.now() - startTime);
|
|
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
|
|
try {
|
|
const {BinaryTree} = dataStructureTyped;
|
|
const tree = new BinaryTree();
|
|
tree.add(3);
|
|
tree.add(12);
|
|
tree.addMany([1, 6, 9, 8,5,2,3,4,7])
|
|
tree.add(10);
|
|
console.log(tree.isPerfectlyBalanced());
|
|
tree.print();
|
|
|
|
const node3 = tree.getNode(3);
|
|
if (node3) node3.right = tree.createNode(1);
|
|
console.log(tree.isPerfectlyBalanced());
|
|
tree.print();
|
|
|
|
tree.clear();
|
|
tree.addMany([1, null, 2, null, 3, null, 4, null, 5, null, 6, null]);
|
|
console.log(tree.isPerfectlyBalanced());
|
|
tree.print();
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
|