logo CodeStepByStep logo


Language/Type: C++ array lists arrays
Author: Marty Stepp (on 2016/06/16)

Write a member function named removeDuplicates that could be added to the ArrayIntList class. Your function should remove any duplicate elements from the list, such that after a call to your function, the list will contain a set of unique elements. To simplify the problem, we will assume that the list is sorted, so that all duplicates occur consecutively. Suppose an ArrayIntList variable named list stores the following values:

{7, 7, 18, 18, 18, 18, 21, 39, 39, 42, 42, 42}

After a call of list.removeDuplicates(); , the list should store the following values:

{7, 18, 21, 39, 42}

If the list is empty or does not contain any duplicate values, calling your function should have no effect.

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 {
    int* elements;   // array storing element data
    int mysize;      // number of elements in the array
    int capacity;    // array's length
    your code goes here;
Type your C++ solution code here:

This is a member function problem. Submit a member function that will become part of an existing C++ class. You do not need to write the complete class, just the member function described in the problem.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.