Right sidebar and return to the top right sidebar code SPONGEBOB

2023-01-10   ES  

  Foreword:During the recursive process, the book was used as an example of the Hanoi Tower. There are very few code, but I do not understand the principle of writing, so I gradually analyzed and recorded the changes of each variable, and expressed its processes in the form of figures in the form of figures. , For future review!

———————————————————————————————————————————————————————————–

Program code (three -order examples):

#include <stdio.h> 

 void Hanoi (Int n, char a, char b, char) // Move the n disc from the A -pillar to the C -pillar, and use B as the auxiliary column 
 {{ 
 if (n == 1) 
 {{ 
 Printf (" %c-> %c \ n", a, c); // Move the disc from A to C 
 } 
 else 
 {{ 
 hanoi (n-1, a, c, b); // Move the disc number 1 to N-1 on A to B, C as auxiliary tower 
 Printf (" %c-> %c \ n", a, c); // Move the disc from A to C 
 hanoi (n-1, b, a, c); // Move the disc number 1 to N-1 on B to C, A as auxiliary tower 
 } 
 } 


 int Main (int argc, char ** argv) { 
 hanoi (3, 'a', 'b', 'c'); // third -order Hanoi Tower 

 Return 0; 
 }

diagram analysis:

Among them, I think the understanding and assignment problem of the understanding and assignment of HANOI (INT N, Char A, Char B, Char C) each time is where the understanding and assignment of the cosmetics of C, and c, it is a place that plagues me.

Welcome to discuss the problem together!

If there are incorrect places, please do not rigid!

Thank you for reading!

source

Related Posts

bzoj1677: [USACO2005 JAN] SumSets

SDUT minimum intercept system Guojing

Oracle Clob field Insertation The character is too long

HOMEBREW Uninstall: FaiLED to Locate Homebrew! Wrong Flyinginthe

Right sidebar and return to the top right sidebar code SPONGEBOB

Random Posts

database engineering -mybatis (1)

[Compulsory] Principles of artificial intelligence Learning Notes (1) Chapter1 Introduction

Set up LAMP services (Apache, MySQL, PHP)

Retis distributed lock (optimistic lock) Nicolos based on LUA script

Electric Vehicle AMT shifting law Study -Calculation of shifting points