Question: Two-Dimensional, Polymorphic Arrays The Rust standard library provides the Vec, which implements polymorphic one-dimensional arrays. Now, a two-dimensional analog of a vector is usually referred
Two-Dimensional, Polymorphic Arrays The Rust standard library provides the Vec, which implements polymorphic one-dimensional arrays. Now, a two-dimensional analog of a vector is usually referred to as a matric but the term 'matrix' carries the connotation of containing numbers and being used for linear algebra. Since the purpose here will be to support images (2-dimensional collections of pixels), we will use the term array. For this part of the assignment, you'll adapt the vector abstraction to support two-dimensional arrays. Your adaptation will be called Array2 and should be polymorphic, just as Vec is polymorphic. Your adaptation should include the following changes when compared to a Vec: . Instead of a length, an Array2 will have a width and a height. Instead of being identified by a single index, an element of an Array2 will be identified by two indices: the column or x index measures the distance between the element and the left edge of the array, while the row or y index measures the distance between the element and the top row of the array. Thus the top left element is always indexed by the pair (0,0). . You will want to support several kinds of iterators on your array. In par- ticular, you must support row-major and column-major iteration. We suggest you name these functions iter_row_major and iter_col_major, respectively. Row-major refers to visiting every element of the first row in order by column, followed by every element of the second row, and so forth. Column-major refers to visiting every element of the first (left-most) column, followed by every element of the second column, and so forth. Recall that an Iterator implementation has a next() function, as well as an Item defined. - An Item need not just be the T element contained within your array2; it could be a data structure with more information about where that T lives in your array2, for instance. - A common "lightweight" data structure to use here is a tuple, whose elements can be accessed by index rather than name.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
