pull/676/head
krahets 1 year ago
parent 71074d88f6
commit 08e4924054

@ -6,12 +6,14 @@
#include "../utils/common.h"
/* 数组表示下的二叉树类 */
struct arrayBinaryTree {
vector *tree;
};
typedef struct arrayBinaryTree arrayBinaryTree;
/* 构造函数 */
arrayBinaryTree *newArrayBinaryTree(vector *arr) {
arrayBinaryTree *newABT = malloc(sizeof(arrayBinaryTree));
newABT->tree = arr;

@ -28,7 +28,7 @@ function dfs(i, src, buf, tar) {
}
/* 求解汉诺塔 */
function solveHanota(A, B, C) {
function hanota(A, B, C) {
const n = A.length;
// 将 A 顶部 n 个圆盘借助 B 移到 C
dfs(n, A, B, C);
@ -44,7 +44,7 @@ console.log(`A = ${JSON.stringify(A)}`);
console.log(`B = ${JSON.stringify(B)}`);
console.log(`C = ${JSON.stringify(C)}`);
solveHanota(A, B, C);
hanota(A, B, C);
console.log('圆盘移动完成后:');
console.log(`A = ${JSON.stringify(A)}`);

@ -28,7 +28,7 @@ function dfs(i: number, src: number[], buf: number[], tar: number[]): void {
}
/* 求解汉诺塔 */
function solveHanota(A: number[], B: number[], C: number[]): void {
function hanota(A: number[], B: number[], C: number[]): void {
const n = A.length;
// 将 A 顶部 n 个圆盘借助 B 移到 C
dfs(n, A, B, C);
@ -44,7 +44,7 @@ console.log(`A = ${JSON.stringify(A)}`);
console.log(`B = ${JSON.stringify(B)}`);
console.log(`C = ${JSON.stringify(C)}`);
solveHanota(A, B, C);
hanota(A, B, C);
console.log('圆盘移动完成后:');
console.log(`A = ${JSON.stringify(A)}`);

Loading…
Cancel
Save