dimanche 12 avril 2020

How do I find unique words from vector and put them into another vector?

I have tried making this function, but with no success. I am just starting c++ and can not seem to figure this out.

vector<string> findUniqueWords(vector<string> vardi){
    vector<string> unikVardi;
    unikVardi.push_back(vardi[0]);
    for (int i = 1; i < vardi.size(); i++){
        for(int k = 0; k < unikVardi.size(); k++){
            if (vardi[i] != unikVardi[k]){
                unikVardi.push_back(vardi[i]);
            }
        }

     return unikVardi;
    }

}

Aucun commentaire:

Enregistrer un commentaire