Question: Consider a C + + program which tries to remove duplicate elements in an array arr. It has a function with a prototype of void

Consider a C++ program which tries to remove duplicate elements in an array arr. It has a function with a prototype of void remove_duplicates (int arr[], int &n);, with
being the number of elements of arr. For example, let int arr[6]={3,6,7,7,7,9};, then the expected array is [3,6,7,9].
Say a student implements such function as follows:
1. void remove_duplicates (int arr[], int &n){
2. int index =0;
3. for (int i =1; i < n; i++){
4. int j =0;
5. while (j <= index && arr[j]!= arr[i])
6. j++;
7. if (j > index)
8. arr[index++]= arr[i];
9.}
10. n = index +1;
11.}
Does this function do the job? If not, which line of code has errors (considering any type of error)?
Group of answer choices
Line 6
Line 8
There are no errors.
Line 3
Line 5
Line 7
Line 10
Line 2

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 Programming Questions!