mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-24 04:33:09 +08:00
Retranslate the complete English edition from Simplified Chinese (#2010)
* Retranslate the complete English edition from Simplified Chinese * Polish three English explanations after reader-focused review
This commit is contained in:
@@ -6,9 +6,9 @@
|
||||
|
||||
#include "../utils/common.hpp"
|
||||
|
||||
/* Move a disk */
|
||||
/* Move one disk */
|
||||
void move(vector<int> &src, vector<int> &tar) {
|
||||
// Take out a disk from the top of src
|
||||
// Take a disk from the top of src
|
||||
int pan = src.back();
|
||||
src.pop_back();
|
||||
// Place the disk on top of tar
|
||||
@@ -17,14 +17,14 @@ void move(vector<int> &src, vector<int> &tar) {
|
||||
|
||||
/* Solve the Tower of Hanoi problem f(i) */
|
||||
void dfs(int i, vector<int> &src, vector<int> &buf, vector<int> &tar) {
|
||||
// If there is only one disk left in src, move it directly to tar
|
||||
// If only one disk remains to be moved from src, move it directly to tar
|
||||
if (i == 1) {
|
||||
move(src, tar);
|
||||
return;
|
||||
}
|
||||
// Subproblem f(i-1): move the top i-1 disks from src to buf using tar
|
||||
dfs(i - 1, src, tar, buf);
|
||||
// Subproblem f(1): move the remaining disk from src to tar
|
||||
// Subproblem f(1): move the remaining disk of this subproblem from src to tar
|
||||
move(src, tar);
|
||||
// Subproblem f(i-1): move the top i-1 disks from buf to tar using src
|
||||
dfs(i - 1, buf, src, tar);
|
||||
@@ -37,9 +37,9 @@ void solveHanota(vector<int> &A, vector<int> &B, vector<int> &C) {
|
||||
dfs(n, A, B, C);
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
/* Driver code */
|
||||
int main() {
|
||||
// The tail of the list is the top of the rod
|
||||
// The end of each list represents the top of the peg
|
||||
vector<int> A = {5, 4, 3, 2, 1};
|
||||
vector<int> B = {};
|
||||
vector<int> C = {};
|
||||
@@ -54,7 +54,7 @@ int main() {
|
||||
|
||||
solveHanota(A, B, C);
|
||||
|
||||
cout << "After disk movement:\n";
|
||||
cout << "After moving all disks:\n";
|
||||
cout << "A =";
|
||||
printVector(A);
|
||||
cout << "B =";
|
||||
|
||||
Reference in New Issue
Block a user