Nov-14-2018, 08:14 AM
Hi,
I use this website to visualize the step.
However, I cannot seem to understand the step 31 to 32 from the aforementioned website of the code below.
At step 31, the code is at the for loop in line 5 with i = 0. I thought it did not finish the loop.
Then at step 31 it just jumps to line 17 immediately without finishing the loop.
Could any please explain why it can jump out like that?
Thanks very much.
I use this website to visualize the step.
However, I cannot seem to understand the step 31 to 32 from the aforementioned website of the code below.
At step 31, the code is at the for loop in line 5 with i = 0. I thought it did not finish the loop.
Then at step 31 it just jumps to line 17 immediately without finishing the loop.
Could any please explain why it can jump out like that?
Thanks very much.
def heap_perm(n, A): if n == 1: yield A else: for i in range(n-1): for hp in heap_perm(n-1, A): yield hp if (n % 2) == 1: j=0 else: j=i A[j],A[n-1] = A[n-1],A[j] for hp in heap_perm(n-1, A): yield hp elements=["A","B","C"] for k in heap_perm(len(elements),elements): print(k)