Question: 1. Construct a flowchart to show how to rearrange the elements in an array so that they appear in reverse order. Task Analysis. The
1. Construct a flowchart to show how to rearrange the elements in an array so that they appear in reverse order. Task Analysis. The problem is to move the elements of an array from one place to another so that when the array is read sequentially from the beginning, we get the last element first, the second to last element as the second element, and so on. For example, BOOK KOOB Before reversal After reversal We can do this simply by exchanging the values of two locations taken at a time. We use two variables i and j. The value of i indicates the location on the left, starting from the first location, and that of j indicates the location on the right, starting from the last location. Now we can exchange the values of the ith and the jth locations of the array. After each exchange of values, we increase the value of i by 1 and decrease the value of j by 1 until i>j. Of course, the initial value of i should be 0-one less than the index of the first location, and that of j should be n + 1-one greater than the index of the last location.
Step by Step Solution
3.32 Rating (158 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
