Merge pull request #104 from justin-tse/dev
Fix the PrintUtil.js showTrunks and Update JavaScript and docs' style (Chapter of Tree)
This commit is contained in:
commit
4289aa3c8f
@ -121,7 +121,7 @@ function min(root) {
|
|||||||
/* Driver Code */
|
/* Driver Code */
|
||||||
/* 初始化二叉搜索树 */
|
/* 初始化二叉搜索树 */
|
||||||
var nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
var nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
||||||
BinarySearchTree(nums)
|
BinarySearchTree(nums);
|
||||||
console.log("\n初始化的二叉树为\n");
|
console.log("\n初始化的二叉树为\n");
|
||||||
printTree(getRoot());
|
printTree(getRoot());
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ n1.left = n2;
|
|||||||
n1.right = n3;
|
n1.right = n3;
|
||||||
n2.left = n4;
|
n2.left = n4;
|
||||||
n2.right = n5;
|
n2.right = n5;
|
||||||
console.log("\n初始化二叉树\n")
|
console.log("\n初始化二叉树\n");
|
||||||
printTree(n1)
|
printTree(n1);
|
||||||
|
|
||||||
/* 插入与删除结点 */
|
/* 插入与删除结点 */
|
||||||
let P = new Tree.TreeNode(0);
|
let P = new Tree.TreeNode(0);
|
||||||
|
@ -8,7 +8,7 @@ const { arrToTree } = require("../include/TreeNode");
|
|||||||
const { printTree } = require("../include/PrintUtil");
|
const { printTree } = require("../include/PrintUtil");
|
||||||
|
|
||||||
// 初始化列表,用于存储遍历序列
|
// 初始化列表,用于存储遍历序列
|
||||||
var list = []
|
var list = [];
|
||||||
|
|
||||||
/* 前序遍历 */
|
/* 前序遍历 */
|
||||||
function preOrder(root) {
|
function preOrder(root) {
|
||||||
|
@ -79,7 +79,7 @@ function showTrunks(p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showTrunks(p.prev);
|
showTrunks(p.prev);
|
||||||
console.log(p.str);
|
process.stdout.write(p.str);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
* Definition for a binary tree node.
|
* Definition for a binary tree node.
|
||||||
*/
|
*/
|
||||||
function TreeNode(val, left, right) {
|
function TreeNode(val, left, right) {
|
||||||
this.val = (val === undefined ? 0 : val) // 结点值
|
this.val = (val === undefined ? 0 : val); // 结点值
|
||||||
this.left = (left === undefined ? null : left) // 左子结点指针
|
this.left = (left === undefined ? null : left); // 左子结点指针
|
||||||
this.right = (right === undefined ? null : right) // 右子结点指针
|
this.right = (right === undefined ? null : right); // 右子结点指针
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,9 +65,9 @@ comments: true
|
|||||||
```js title=""
|
```js title=""
|
||||||
/* 链表结点类 */
|
/* 链表结点类 */
|
||||||
function TreeNode(val, left, right) {
|
function TreeNode(val, left, right) {
|
||||||
this.val = (val === undefined ? 0 : val) // 结点值
|
this.val = (val === undefined ? 0 : val); // 结点值
|
||||||
this.left = (left === undefined ? null : left) // 左子结点指针
|
this.left = (left === undefined ? null : left); // 左子结点指针
|
||||||
this.right = (right === undefined ? null : right) // 右子结点指针
|
this.right = (right === undefined ? null : right); // 右子结点指针
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user