logo CodeStepByStep logo

mirror

Language/Type: C++ array lists arrays

Write a member function named mirror that could be added to the ArrayIntList class. Your function should double the size of the list of integers by appending the mirror image of the original sequence to the end of the list. The mirror image is the same sequence of values in reverse order. For example, suppose a variable named list stores the following values:

{1, 3, 2, 7}

If we make the call of list.mirror(); then it should store the following values after the call:

{1, 3, 2, 7, 7, 2, 3, 1}

The list has been doubled in size by having the original sequence appearing in reverse order at the end of the list. If the list is empty, it should also be empty after the call.

Constraints: You may call other private member functions of the ArrayIntList if you like, but not public ones. Do not make assumptions about how many elements are in the list or about the list's capacity. Do not use any auxiliary data structures to solve this problem (no array, vector, stack, queue, string, etc).

Write the member function as it would appear in ArrayIntList.cpp. You do not need to declare the function header that would appear in ArrayIntList.h. Assume that you are adding this method to the ArrayIntList class as defined below:

class ArrayIntList {
private:
    int* elements;   // array storing element data
    int mysize;      // number of elements in the array
    int capacity;    // array's length

public:
    ...
};
Member function: Write a member function that will become part of an existing class. You do not need to write the complete class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.