https://github.com/xuerzong/data-structure
Data structures implemented by typescript.
https://github.com/xuerzong/data-structure
data-structure data-structures linked-list queue stack tree typescript
Last synced: 2 months ago
JSON representation
Data structures implemented by typescript.
- Host: GitHub
- URL: https://github.com/xuerzong/data-structure
- Owner: xuerzong
- Created: 2022-05-04T08:30:18.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-13T08:04:45.000Z (over 2 years ago)
- Last Synced: 2025-10-19T00:46:18.144Z (8 months ago)
- Topics: data-structure, data-structures, linked-list, queue, stack, tree, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@xuerzong/data-structure
- Size: 121 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# data-structure
Data structures implemented by typescript.
## How to use
```bash
yarn add @xuerzong/data-structure
```
### BinaryTree
```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]
```
## To do list
- [x] Queue
- [x] Stack
- [x] LinkedList
- [x] BinaryTree
## License
[MIT](./LICENSE)