EDIT:
Ok so the REAL question here is how do I sort the following......
I have an array a[] of string
I have an array b[] that is like the position of the elements in the string.
E.g a[] = {6,5,4,3,2,1}
b[] = {0,1,2,3,4,5}
How do I then sort this to show the following:
a[] = {1,2,3,4,5,6}
b[] = {5,4,3,2,1,0}
whilst trying to keep nlog(n) complexity
This will RESOLVE my issue entirely!
Hey Guys
I am having some trouble with a function in C++
These are the specifications for the function:
I have started the function, but am feeling pretty lost in where to go next. Also trying to figure out how to ensure the complexity stays nlog(n)
Thanks for your help!
Edited by RadMabbit - 9/25/12 at 11:20pm
Ok so the REAL question here is how do I sort the following......
I have an array a[] of string
I have an array b[] that is like the position of the elements in the string.
E.g a[] = {6,5,4,3,2,1}
b[] = {0,1,2,3,4,5}
How do I then sort this to show the following:
a[] = {1,2,3,4,5,6}
b[] = {5,4,3,2,1,0}
whilst trying to keep nlog(n) complexity
This will RESOLVE my issue entirely!
Hey Guys
I am having some trouble with a function in C++
These are the specifications for the function:
- 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.
I have started the function, but am feeling pretty lost in where to go next. Also trying to figure out how to ensure the complexity stays nlog(n)
Code:
int listdistinct(string b[], int n) {
string a[];
sort b[];
i=1;
for i=0 , i<k {
if b[i] == b[i-1] ;
else { a[n] = b[i-1]; n++;}
}
return n;
Thanks for your help!
Edited by RadMabbit - 9/25/12 at 11:20pm






