mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 22:28:40 +08:00 
			
		
		
		
	Finetune
This commit is contained in:
		@ -6,12 +6,14 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "../utils/common.h"
 | 
					#include "../utils/common.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 数组表示下的二叉树类 */
 | 
				
			||||||
struct arrayBinaryTree {
 | 
					struct arrayBinaryTree {
 | 
				
			||||||
    vector *tree;
 | 
					    vector *tree;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct arrayBinaryTree arrayBinaryTree;
 | 
					typedef struct arrayBinaryTree arrayBinaryTree;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 构造函数 */
 | 
				
			||||||
arrayBinaryTree *newArrayBinaryTree(vector *arr) {
 | 
					arrayBinaryTree *newArrayBinaryTree(vector *arr) {
 | 
				
			||||||
    arrayBinaryTree *newABT = malloc(sizeof(arrayBinaryTree));
 | 
					    arrayBinaryTree *newABT = malloc(sizeof(arrayBinaryTree));
 | 
				
			||||||
    newABT->tree = arr;
 | 
					    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;
 | 
					    const n = A.length;
 | 
				
			||||||
    // 将 A 顶部 n 个圆盘借助 B 移到 C
 | 
					    // 将 A 顶部 n 个圆盘借助 B 移到 C
 | 
				
			||||||
    dfs(n, A, 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(`B = ${JSON.stringify(B)}`);
 | 
				
			||||||
console.log(`C = ${JSON.stringify(C)}`);
 | 
					console.log(`C = ${JSON.stringify(C)}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
solveHanota(A, B, C);
 | 
					hanota(A, B, C);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
console.log('圆盘移动完成后:');
 | 
					console.log('圆盘移动完成后:');
 | 
				
			||||||
console.log(`A = ${JSON.stringify(A)}`);
 | 
					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;
 | 
					    const n = A.length;
 | 
				
			||||||
    // 将 A 顶部 n 个圆盘借助 B 移到 C
 | 
					    // 将 A 顶部 n 个圆盘借助 B 移到 C
 | 
				
			||||||
    dfs(n, A, 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(`B = ${JSON.stringify(B)}`);
 | 
				
			||||||
console.log(`C = ${JSON.stringify(C)}`);
 | 
					console.log(`C = ${JSON.stringify(C)}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
solveHanota(A, B, C);
 | 
					hanota(A, B, C);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
console.log('圆盘移动完成后:');
 | 
					console.log('圆盘移动完成后:');
 | 
				
			||||||
console.log(`A = ${JSON.stringify(A)}`);
 | 
					console.log(`A = ${JSON.stringify(A)}`);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user