I am intenting sort an array of strings with this code:
void sort(string scadena[]){
string temp;
//here i am intenting sort the elements. it works fine
for(int i=0;i<m;i++){
for(int j=i+1;j<m;j++){
if(scadena[i]>scadena[j]){
temp=scadena[i];
scadena[i]=scadena[j];
scadena[j]=temp;
}
}
}
// Here i am intenting remove the repeated elements, but it not works fine.
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(scadena[i]==scadena[j] && j!=i){
for(int k=j;k <m; k++){
scadena[k]=scadena[k+1];
}
m--;
}
}
}
//Because when i do the cout, the output has repeated elements. it not works
for(int i=0;i<m;i++){
cout<<i<<") "<<scadena[i]<<endl;
}
}
The output has repeated elements, but i do not why.
The full code has a function that do the permutation of strings.
I do not what happen.