An open API service indexing awesome lists of open source software.

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.

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)