If necessary, open the Cleanup Animator and choose the Shuffle Left algorithm from the Select Algorithm drop-down list. Click Run and observe the "loop inside a loop" nature of this algorithm by watching the animation. The general idea is that the L marker moves to the right trying to detect 0s. Each time it detects a 0, the R marker moves to the right, shuffling the data items to the left. Try this three or four times, remembering to click Reset to prepare for each run. Suppose the original data set consists of these numbers: What is the final arrangement of the data when the algorithm terminates?

Respuesta :

Answer:

A = 42 32 0 0 0 77 23 71 is the list of numbers taken here as the question is incomplete.

L marker moves to the right trying to detect 0s. Each time it detects a 0, the R marker moves to the right, shuffling the data items to the left.

Get the array, A and its size, n

L = 1

R = 2

Repeat the following steps until left > legit

if AL ≠ 0

L ++

R ++

else

legit --

Repeat the following steps until right > n

Copy AR to AR

R ++

R = L + 1

stop

Explanation: The arrangement of data is as follows:

A = 42 32 0 0 0 77 23 71

N = 8; L= 1; R = 2

Iteration 1: 42 ≠ 0 => L = 2; R = 3

A = 42 32 0 0 0 77 23 71

Iteration 2: 32 ≠ 0 => L = 3; R = 4

A = 42 32 0 0 0 77 23 71

Iteration 3: 0 = 0 => N = 7

Copy the remaining elements one position to its left

A = 42 32 0 0 77 23 71

Iteration 4: 0 = 0 => N = 6

Copy the remaining elements one position to its left

A = 42 32 0 77 23 71

Iteration 5: 0 = 0 => N = 5

Copy the remaining elements one position to its left

A = 42 32 77 23 71

Iteration 6: 77 ≠ 0 => L = 4; R = 5

A = 42 32 77 23 71

Iteration 7: 23 ≠ 0 => L= 5; R = 6

A = 42 32 77 23 71

Iteration 8: 71 ≠ 0 => L= 6; R = 7

A = 42 32 77 23 71

L > N ---- stop

final arrangement of the data when the algorithm terminates

42 32 77 23 71