In this solution, the functions with small, fast implementations are inlined. Alternatively, the inlinekeyword can be removed and the function definitions moved to Sequence.cpp. (inline will be mentioned at some point in class, so don't worry if you've never seen it before.)
Notice which member functions are const, and observe the use of the type alias ItemTy
// Later in the course, we'll see that templates provide a much nicer
// way of enabling us to have Sequences of different types. For now,
// we'll use a type alias
int insert(int pos, const ItemType& value);
// Insert value into the sequence so that it becomes the item at
// position pos. The original item at position pos and those that
// follow it end up at positions one higher than they were at before.
// Return pos if 0 <= pos <= size() and the value could be
// inserted. (It might not be, if the sequence has a fixed capacity,
// e.g., because it's implemented using a fixed-size array.) Otherwise,
// leave the sequence unchanged and return -1. Notice that
// if pos is equal to size(), the value is inserted at the end.
Get Free Quote!
301 Experts Online