See the assignment turn-in page (last modified on 4 March 2002) for instructions on turning in your assignment.
Two array sequences can be catenated together to form a new array sequence. The new array sequence contains n1 + n2 elements, where the original sequences contain n1 and n2 elements, respectively.
Given an array sequence as
that contains n elements and two indices 0
<= i <= j <= n, as
can be sliced at the index range
(i, j) to form a new array sequence. The new array sequence contains
j - i elements and has the following relation to the original array
sequence:
If j is less than i, the index range (i, j) is invalid.
class array_sequence { public: // The array-sequence element type. typedef int etype; // Create an empty array sequence. array_sequence(); // Create an array sequence contining the single value e. array_sequence(const etype & e); // Create the array sequence containing, in left-to-right order, the values // contained in the pointer range (beg, end). array_sequence(const etype * beg, const etype * end); // Return the element at index i, or die with an error message if i is out // of range. etype get(unsigned i) const; // Replace the element at index i with the element e; die with an error // message if i is out of range. void put(unsigned i, const etype & e); // Return an array sequence holding the values in the index range (i, j); // die with an error message if (i, j) is not a valid index range. array_sequence slice(unsigned i, unsigned j) const; // Return the array sequence that is the catenation of this array sequence // with the given sequence. array_sequence concat(const array_sequence & as) const; // Return the number of elements in this sequence. unsigned size(void) const; };
Your implementation should be efficient in that all operations except for the range constructor should take sub-linear time to perform.
This page last modified on 12 November 2002.