-
It is not possible to use recursion. Is it all done all at once?
Why do you have to have 300 lines?
-
What you wrote yourself is similar to the one upstairs!
-
I don't understand, if I'm not satisfied, I'll leave it at the bottom! Anyway, it's all buckle!
-
iphone5 has been using navigation for a long time without power?
-
The recursive algorithm was written by me a few days ago, and the non-recursive algorithm is what I just found, and it contains both recursion and non-recursion.
Recursive algorithm: include
Recursively seeking the Tower of Hanoi problem.
void hanoi(int n, char a, char b, char c, int *time)
Print out the path for each step.
void move(char a, char c)
int main(void)
Non-recursive algorithm:
#include
define maxstack 10 Maximum depth of stack
int c = 1;A global variable that represents the number of steps currently moved
struct hanoi ;
void move(char x, int n, char y) * move function, which means to move a disk from one needle to another *
void hanoi(int n, char x, char y, char z) * recursive algorithm of the Tower of Hanoi*
void push(struct hanoi *p, int top, char x, char y, char z,int n)
void unreverse hanoi(struct hanoi *p) * non-recursive algorithm of the Tower of Hanoi
if (p[top].n == 1)
if (top >= 0) }
int main(void)
-
#include
The X-storey tower of the Tower of Hanoi was moved from Tower A to Tower C in its entirety, with a temporary Tower B in the middle.
X-story towers are stacked from largest to smallest. Only one tower can be moved per move. And in the process of moving, it is necessary to ensure that the small layer is on the top.
With the help of Tower B, it is possible to move all the X-story towers from A to C and meet the requirements (the larger one is on the bottom and the smaller one is on the top during the move).
int main()
The following is the definition of the tower function.
Parameter analysis: The X-layer tower is placed on A, B is the middle tower, and C is the target tower. That is, the X-story tower has to be moved from A to C.
This function implements the transfer of the X-layer tower from A to C as a whole. And how the whole process is moved.
void tower(int x,char a,char b,char c)}
-
You have to understand recursion to understand this problem first, and it is best to perform it in a single track, so I'll briefly talk about it here!
hanoi(5, 'a', 'b', 'c');Put 5 from'a'Move to'c'
In this case, n=5, noe='a', two='b', three='c'
Because n!=1, execute else.
hanoi( 4, 'a', 'c', 'b');Move the above 4 from A to B
move( 'a', 'c');Move the 5th one from A to C
hanoi( 4, 'b', 'a', 'c');Move those 4 again from B to C
The above is very clear, and then analyze hanoi( 4,'a', 'c', 'b');Moving the above 4 from A to B is also doing else
hanoi( 3, 'a', 'b', 'c');Move the above 3 from A to C
move( 'a', 'b');Move the 4th from A to B
hanoi( 4, 'c', 'a', 'b');Move those 3 again from C to B
It doesn't end until n=1.
-
#include
void move(char a,char b)void f(int n,char a,char b,char c)}void main()
This is my ** The first one is to define a function, and here the recursion is reflected in the function and the function, so it will be calculated again and again until finally the previous n-1 is moved to b, the bottom is moved to c, and the rest is moved from b to c. If there is no return, it should be void here, and there is no return to return the value.
-
According to your program, when n=3 does not satisfy the n=1 condition, so take else and then execute.
hanoi(n-1,one,three,two); // 2 a c b
move(one,three);Call the move function to output c-->b
hanoi(n-1,two,one,three); // 1 a b c
As for why you say that n=1 doesn't execute if(n==1) at this time, it's because your program if and else are not in a loop, and the program will only judge once, if you add a while(n-1!=0) or the for loop will not stop checking the value of n before if.
-
In fact, there are three main steps:
First, move the n-1 disks on A to B via C.
Second, move the bottom disk on A to C.
Third, because n-1 disks are all on B, it is good to repeat the above steps with B as A.
#include
void move(int n,char a,char b,char c)
int main()
With the above factors in mind, we propose two high-efficiency techniques for designing 1-D and 2-D filters based on the decomposition of the amplitude specifications of the given 1-D and 2-D variables [3, 4]. These two techniques are computationally very efficient because they only require the design of a set of 1-d constant filters and about a few 1-d polynomials. In particular, these techniques ensure the stability of the filter that generates variables. >>>More
7742A23 is very good, you can take a look, 6900 can be obtained.
It's useless for you to look this up.
You'd better have his qq uc or something. >>>More
Gypsum turning:
Adjust the gypsum slurry, put water first, and then sprinkle the gypsum, the first time the gypsum must be thin, evenly covered to the surface of the mud, there must be no bubbles, the hemp fiber is dismantled and the hemp fiber is stained with more viscous gypsum, reinforced according to the divided block, covered with the entire clay sculpture, and the gypsum is completely solidified after the whole is removed and dried. >>>More
Father: Son, it's the New Year, let's go and paste the Spring Festival couplets. I'll stick the upper link first, and when you paste the lower link, you can help me see it below, and the upper and lower links should be the same height. If the lower link is lower than the upper link, you say 'high promotion', and if the lower link is higher than the upper link, you say 'get rich'. >>>More