Comparing version 1.1.0 to 1.2.0
MIT License | ||
Copyright (c) 2019 Klaus Sinani <klaussinani@gmail.com> (klaussinani.github.io) | ||
Copyright (c) 2019 - present Klaus Sinani <klaussinani@gmail.com> (klaussinani.github.io) | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "binstree", | ||
"version": "1.1.0", | ||
"description": "🌲 Binary search trees for ES6", | ||
"version": "1.2.0", | ||
"description": "Binary search trees for ES6", | ||
"license": "MIT", | ||
@@ -27,3 +27,4 @@ "repository": "klaussinani/binstree", | ||
"data", | ||
"structure" | ||
"structure", | ||
"typescript" | ||
], | ||
@@ -38,3 +39,3 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "1.4.1", | ||
"ava": "2.1.0", | ||
"coveralls": "^3.0.3", | ||
@@ -41,0 +42,0 @@ "nyc": "^13.3.0", |
@@ -6,3 +6,3 @@ <h1 align="center"> | ||
<h4 align="center"> | ||
🌲 Binary search trees for ES6 | ||
Binary search trees for ES6 | ||
</h4> | ||
@@ -922,3 +922,6 @@ | ||
- [avlbinstree](https://github.com/klaussinani/avlbinstree) - AVL self-balancing binary search trees for ES6 | ||
- [doublie](https://github.com/klaussinani/doublie) - Doubly circular & linear linked lists for ES6 | ||
- [mheap](https://github.com/klaussinani/mheap) - Binary min & max heaps for ES6 | ||
- [prioqueue](https://github.com/klaussinani/prioqueue) - Priority queues for ES6 | ||
- [singlie](https://github.com/klaussinani/singlie) - Singly circular & linear linked lists for ES6 | ||
@@ -925,0 +928,0 @@ |
@@ -103,3 +103,3 @@ 'use strict'; | ||
isPartial() { | ||
return this.degree === 1; | ||
return this.isLeftPartial() || this.isRightPartial(); | ||
} | ||
@@ -106,0 +106,0 @@ |
@@ -258,10 +258,20 @@ 'use strict'; | ||
if (current) { | ||
let sawLeaf = false; | ||
const queue = [current]; | ||
if (!current) { | ||
return true; | ||
} | ||
while (queue.length > 0) { | ||
let leafDepth; | ||
let sawLeaf = false; | ||
let currentDepth = -1; | ||
const queue = [current]; | ||
while (queue.length > 0) { | ||
currentDepth += 1; | ||
let {length: nodes} = queue; | ||
while (nodes > 0) { | ||
current = queue.shift(); | ||
nodes -= 1; | ||
if (current.degree === 1) { | ||
if (current.isPartial()) { | ||
return false; | ||
@@ -271,3 +281,8 @@ } | ||
if (current.isLeaf()) { | ||
if (sawLeaf && leafDepth !== currentDepth) { | ||
return false; | ||
} | ||
sawLeaf = true; | ||
leafDepth = currentDepth; | ||
} else { | ||
@@ -278,3 +293,3 @@ if (sawLeaf) { | ||
queue.push(current.left, current.right); | ||
queue.push(...current.children); | ||
} | ||
@@ -281,0 +296,0 @@ } |
35381
515
934