Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

8. Algorithm Design: Iterative (13 points) An iterative strategy to move any and all zeroes in an array A of n numbers, n21, to the

image text in transcribed

8. Algorithm Design: Iterative (13 points) An iterative strategy to move any and all zeroes in an array A of n numbers, n21, to the left end of the array: 1. Let leftp be a pointer to the leftmost index of A and rightp be a pointer to the rightmost index of A. 2. Move leftp right until leftp is pointing to a cell containing a non-zero number or leftp reaches the right end of A. 3. Move rightp left until rightp is pointing to a cell containing a zero or r reaches the left end of A. 4. If left and right are not equal or have not crossed (passed) each other, swap the numbers in cells pointed to by left and right and repeat 2-4. 5. If left and rightp are equal or have crossed (passed) each other then stop. The corresponding iterative algorithm is given in part below. Complete it. Move-zeroes-iterative(A: array [p..r] of number, r-p20) 1. leftp = p; rightp=r 2. repeat 3. swap(A[leftp), A[rightp]) 4. while leftpsr and 6. while rightpp and 8. until

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions