Question: Write a C++ function int removeDuplicates(int a[ ], int n) that accepts an int array a containing a list of n integers sorted in ascending

Write a C++ function int removeDuplicates(int a[ ], int n) that accepts an int array a containing a list of n integers sorted in ascending order. Note that some of the values in the array may have duplicates as shown in the example below. The function should eliminate all the duplicates and in the meantime compact the array (i.e., closes the gaps created after the removal of all duplicates). The function also returns a value indicating how many unique values are stored in the array. As an illustration, the below diagrams show the contents of the same array before and after the duplicates are remove. The function also returns a value of 4 as there are 4 unique values. Note that since only the first 4 values are relevant, so the three 0s are meaningless. They could be 4, 4, 5 depending how you write your code. Note also that all needed manipulations must take place within the array a; i.e., there is no need to declare another array in the function and in fact, you must not declare addition array insides the function to get the job done. 15%

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!