0
Can anyone help me break it down on what this code is trying to do? Its an array problem c++
int removeDups (string a[], int n){ if (n < 0) return -1; int duplicate = 0; string duplicateString = a[0]; for (int i = 1; i < n; i++){ if(a[i] == duplicateString) a[i] = "duplicate"; else duplicateString = a[i]; } for (int i = 0; i < n; i++){ while (a[i]!= "duplicate" && i<n-1){ i++; } for (int k = i+1; k < n; k++){ while (a[k] == "duplicate" && k < n-1){ k++; } string temp = a[k]; a[k]+a[i]; a[i] = temp; break; } } for (int i = 0; i < n; i++){ if (a[i]!= "duplicate") duplicate++; } return duplicate; }
3 ответов