C++ Function issue involving Distinct Values
<p>Ok guys, I was given an assignment, and I am running into a lot of problems with coding this. </p>

<pre><code># include &lt;string&gt;
using namespace std;
int listdistinct( string b[], int n );
// modifies b so that all the distinct values are in b[0..k-1] and returns k
// the distinct values are in the order of their leftmost appearance in original b
//  e.g.  3,6,3,19,6,3,11  with n=7   would be changed to 3,6,19,11,?,? with k=4 returned
// worstcase complexity is n log(n) or better.
</code></pre>

<p>I was given this as a starter:</p>

<pre><code>int listdistinct(string b[], int n) {
    string a[];
    sort b[];
    i=1;
    for i=0 , i&lt;k {
        if b[i] == b[i-1] ;
        else { a[n] = b[i-1]; n++;}
    }
    return n;
}
</code></pre>

<p>Ok so didnt give the best description of my issue. 
This is how I think I should code it.</p>

<p>b[] = array of numbers,
a[] = destination of numbers without duplicates, and finally, c[] would be an array taking the order of the array before it is sorted. </p>

<p>What I need to do is, match up the length of b[] and add in numbers, say 1 2 3 4 ... etc to c[] to maintain my order. Then I can sort both of those arrays, so the order number stays with the array number in b[]. </p>

<p>I am having an issue knowing how to set the for loop to do this, how many times to repeat it!</p>

<p>I also do not know how to order the array so that the most frequent one comes to the front of the array. </p>

<p>The biggest problem I am having with this is understanding how to do all of this, and keep the algorithm to an n log n worst case complexity.</p>
