Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 2 - Exercises - Page 88: 22

Answer

Let's store the elements in reversed order in the sequence: $R_{1}, R_{2}, \ldots R_{k}$ After that, let's copy the already reversed list back into $N_{1}, N_{2}, \ldots N_{k}$ $\bullet$ Get the value of $k$ $\bullet$ Get the elements of the list $N_{1}, N_{2}, \ldots N_{k}$ $\bullet$ Set the value of $i$ to 1 $\bullet$ While $(i \leq k)$ do $\bullet \quad$ Set value of $R_{i}$ to $N_{k+1-i}$ $\bullet\quad$ Increment $i$ by 1 $\bullet$ End of loop $\bullet$ Set value of $i$ to 1 $\bullet$ While $(i \leq k)$ do $\bullet \quad$ Set value of $N_{i}$ to $R_{i}$ $\bullet\quad$ Increment $i$ by 1 $\bullet$ End of loop $\bullet$ Print the result: $N_{1}, N_{2}, \ldots N_{k}$

Work Step by Step

Let's store the elements in reversed order in the sequence: $R_{1}, R_{2}, \ldots R_{k}$ After that, let's copy the already reversed list back into $N_{1}, N_{2}, \ldots N_{k}$ $\bullet$ Get the value of $k$ $\bullet$ Get the elements of the list $N_{1}, N_{2}, \ldots N_{k}$ $\bullet$ Set the value of $i$ to 1 $\bullet$ While $(i \leq k)$ do $\bullet \quad$ Set value of $R_{i}$ to $N_{k+1-i}$ $\bullet\quad$ Increment $i$ by 1 $\bullet$ End of loop $\bullet$ Set value of $i$ to 1 $\bullet$ While $(i \leq k)$ do $\bullet \quad$ Set value of $N_{i}$ to $R_{i}$ $\bullet\quad$ Increment $i$ by 1 $\bullet$ End of loop $\bullet$ Print the result: $N_{1}, N_{2}, \ldots N_{k}$
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.