Problem

The point of this exercise is to demonstrate that an object that behaves like an iterator...

The point of this exercise is to demonstrate that an object that behaves like an iterator is an iterator. More precisely, if an object accesses some container and behaves like an iterator of a particular strength, then that object can be used as an iterator to manipulate the container with any of the generic functions that require an iterator having that strength. However, while the generic algorithms can be used with this container, the member functions, such as begin and end, will (of course) not be present (for example, in an array) unless they have been explicitly coded for that container. We will restrict this exercise to arrays of double, but the same message would hold true for any base type.

a. Argue from the properties of random-access iterators that a pointer that points to an element of an array behaves exactly as a random-access iterator.

b. Argue further that

i) the name of the array is a pointer to double that points to the first element and so the array name can serve as a “begin” iterator and

ii) (the array’s name) + (the size of the array) can serve as an “end” pointer. (Of course, this points one past the end, as it should.)

c. Write a short program in which you declare an array of double of size 10, and populate this array with 10 doubles. Then call the sort generic algorithm with these pointer values as arguments and display the results.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 19