Comparing version 0.1.2 to 0.1.3
@@ -11,3 +11,4 @@ declare class BinaryNode { | ||
insert(data: (number | null)[]): BinaryNode | null | undefined; | ||
levelOrder(): (number | undefined)[][]; | ||
} | ||
export {}; |
@@ -54,4 +54,27 @@ "use strict"; | ||
}; | ||
BinaryTree.prototype.levelOrder = function () { | ||
var queue = []; | ||
var levels = []; | ||
queue.push(this.root); | ||
while (queue.length) { | ||
var level = []; | ||
var levelSize = queue.length; | ||
var count = 0; | ||
while (count < levelSize) { | ||
var current = queue.shift(); | ||
count += 1; | ||
level.push(current === null || current === void 0 ? void 0 : current.value); | ||
if (current === null || current === void 0 ? void 0 : current.left) { | ||
queue.push(current.left); | ||
} | ||
if (current === null || current === void 0 ? void 0 : current.right) { | ||
queue.push(current.right); | ||
} | ||
} | ||
levels.push(level); | ||
} | ||
return levels; | ||
}; | ||
return BinaryTree; | ||
}()); | ||
exports.BinaryTree = BinaryTree; |
{ | ||
"name": "flex-algo", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "\"SDK for commonly used data structure and algorithms\"", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8347
196