You're right - you are pretty close. In your compare function, you may want to consider starting the inner
j
loop at the current value of
i+1
Also your
if
statement does not want to compare
arr[j]
with the concatenated string
a
- rather the comparison should be between
arr[i]
and
arr[j]
Finally, I do not believe that you want to concatenate
arr[j]
onto the end of
a
inside the inner loop. Instead, consider initialising a
bool
at the beginning of the outer
i
loop, for example:
1 2 3
|
for(int i = 0; i < n; i++)
{
bool bFoundDuplicate = false;
|
Then in your inner
j
loop, you want an
if
statement that will set this
bool
to true if you have found a duplicate.
Just before the outer
i
loop finishes, only append
arr[i]
onto
a
if no duplicates have been found, i.e.
1 2 3 4
|
} // End of j loop
if( ! bFoundDuplicate )
a = a + arr[i] + " ";
} // End of i loop
|
And of course you'll need to get the
a
string out of this function, perhaps by setting the function's return type to string and returning
a
at the end.
Hope that makes sense!