Skip to content

Commit 2a8813f

Browse files
committed
init
0 parents  commit 2a8813f

11 files changed

+5270
-0
lines changed

Diff for: .gitignore

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
.idea
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
lerna-debug.log*
10+
.pnpm-debug.log*
11+
12+
# Diagnostic reports (https://nodejs.org/api/report.html)
13+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
14+
15+
# Runtime data
16+
pids
17+
*.pid
18+
*.seed
19+
*.pid.lock
20+
21+
# Directory for instrumented libs generated by jscoverage/JSCover
22+
lib-cov
23+
24+
# Coverage directory used by tools like istanbul
25+
coverage
26+
*.lcov
27+
28+
# nyc test coverage
29+
.nyc_output
30+
31+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32+
.grunt
33+
34+
# Bower dependency directory (https://bower.io/)
35+
bower_components
36+
37+
# node-waf configuration
38+
.lock-wscript
39+
40+
# Compiled binary addons (https://nodejs.org/api/addons.html)
41+
build/Release
42+
43+
# Dependency directories
44+
node_modules/
45+
jspm_packages/
46+
47+
# Snowpack dependency directory (https://snowpack.dev/)
48+
web_modules/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Optional stylelint cache
60+
.stylelintcache
61+
62+
# Microbundle cache
63+
.rpt2_cache/
64+
.rts2_cache_cjs/
65+
.rts2_cache_es/
66+
.rts2_cache_umd/
67+
68+
# Optional REPL history
69+
.node_repl_history
70+
71+
# Output of 'npm pack'
72+
*.tgz
73+
74+
# Yarn Integrity file
75+
.yarn-integrity
76+
77+
# dotenv environment variable files
78+
.env
79+
.env.development.local
80+
.env.test.local
81+
.env.production.local
82+
.env.local
83+
84+
# parcel-bundler cache (https://parceljs.org/)
85+
.cache
86+
.parcel-cache
87+
88+
# Next.js build output
89+
.next
90+
out
91+
92+
# Nuxt.js build / generate output
93+
.nuxt
94+
dist
95+
96+
# Gatsby files
97+
.cache/
98+
# Comment in the public line in if your project uses Gatsby and not Next.js
99+
# https://nextjs.org/blog/next-9-1#public-directory-support
100+
# public
101+
102+
# vuepress build output
103+
.vuepress/dist
104+
105+
# vuepress v2.x temp and cache directory
106+
.temp
107+
.cache
108+
109+
# Docusaurus cache and generated files
110+
.docusaurus
111+
112+
# Serverless directories
113+
.serverless/
114+
115+
# FuseBox cache
116+
.fusebox/
117+
118+
# DynamoDB Local files
119+
.dynamodb/
120+
121+
# TernJS port file
122+
.tern-port
123+
124+
# Stores VSCode versions used for testing VSCode extensions
125+
.vscode-test
126+
127+
# yarn v2
128+
.yarn/cache
129+
.yarn/unplugged
130+
.yarn/build-state.yml
131+
.yarn/install-state.gz
132+
.pnp.*

Diff for: README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Binary Search Tree
2+
3+
This is an implementation of a [binary search tree](https://en.wikipedia.org/wiki/Binary_search_tree) in node.js. This implementation ignores duplicate values. Integer values are supported by default but there is support for implementing a custom comparison function. See `objectComparator` for one possible example of how this can be achieved.
4+
5+
## Getting Started:
6+
```
7+
$ npm install
8+
$ npm test # if you'd like to run the tests
9+
```
10+
11+
## Usage:
12+
```
13+
const { BinarySearchTree } = require('./index')
14+
15+
const bst = new BinarySearchTree([26, 82, 16, 92, 33])
16+
const { deepest, depth } = bst.getDeepestNodesAndDepth()
17+
console.log(`deepest: ${deepest}; depth ${depth}`)
18+
```
19+
20+
## Reference:
21+
Constructor accepts two optional arguments:
22+
23+
1. An array of initialization values
24+
2. A comparator function for custom comparisons. By default, this will be `integerComparator`
25+
26+
27+
**`insert(val)`** - insert an individual value
28+
29+
**`search(val)`** - returns `true` or `false` depending on whether the given `val` was found in the tree
30+
31+
**`delete(val)`** - delete a value from the tree
32+
33+
**`traverse(val)`** - traverses the tree and outputs the values in order
34+
35+
**`getDeepestNodesAndDepth()`** - returns an object with keys `deepest` and `depth` representing the values found at the deepest level of the tree along with the depth of the tree

Diff for: index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module.exports = require('./src/main/index')
2+

0 commit comments

Comments
 (0)