0.3.3 • Published 1 year ago

@xuerzong/data-structure v0.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

  • Queue
  • Stack
  • LinkedList
  • BinaryTree

License

MIT

0.3.2

1 year ago

0.3.3

1 year ago

0.3.1

1 year ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago