@xuerzong/data-structure
TypeScript icon, indicating that this package has built-in type declarations

0.3.3 • Public • Published

data-structure

Data structures implemented by typescript.

How to use

yarn add @xuerzong/data-structure

BinaryTree

import { BinaryTree, BinaryTreeNode } from '@xuerzong/data-structure'

type TreeNode = BinaryTreeNode<number>

/**
 * @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

Package Sidebar

Install

npm i @xuerzong/data-structure

Weekly Downloads

1

Version

0.3.3

License

MIT

Unpacked Size

57.7 kB

Total Files

41

Last publish

Collaborators

  • xuerzong