fix: the bug for the array binary tree from ts and js code (#936)

This commit is contained in:
Justin Tse 2023-11-13 14:06:17 +08:00 committed by GitHub
parent 1f71f6f701
commit 2b0cf6f9ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -40,7 +40,7 @@ class ArrayBinaryTree {
/* 获取索引为 i 节点的父节点的索引 */
parent(i) {
return (i - 1) / 2;
return Math.floor((i - 1) / 2); // 向下取整
}
/* 层序遍历 */

View File

@ -42,7 +42,7 @@ class ArrayBinaryTree {
/* 获取索引为 i 节点的父节点的索引 */
parent(i: number): number {
return (i - 1) / 2;
return Math.floor((i - 1) / 2); // 向下取整
}
/* 层序遍历 */
@ -148,4 +148,4 @@ console.log('中序遍历为:' + res);
res = abt.postOrder();
console.log('后序遍历为:' + res);
export {};
export { };