Data structures implemented by typescript.
npm install @xuerzong/data-structureData structures implemented by typescript.
``bash`
yarn add @xuerzong/data-structure
`typescript
import { BinaryTree, BinaryTreeNode } from '@xuerzong/data-structure'
type TreeNode = BinaryTreeNode
/**
* @reference https://leetcode.cn/problems/invert-binary-tree/
*/
function invertTree(root: TreeNode | null): TreeNode | null {
if(root === null) {
return root
}
[root.left, root.right] = [root.right, root.left]
invertTree(root.left)
invertTree(root.right)
return root
}
const tree = BinaryTree.generate(...[2, 1, 3])
invertTree(tree.root)
console.log(tree.bfs()) // [2, 3, 1]
``
- [x] Queue
- [x] Stack
- [x] LinkedList
- [x] BinaryTree