hi I am working on a c++ program to insert certain objects which has string as an attribute into a map. How to insert the objects keeping them sorted alphabetically
The code below is sample code for vector. I need to implement the same using map
Word *WordVector::insert(const string text){
Word newWord(text);
if(data.size()==0)
{
data.push_back(newWord);
}
else{
auto insert_itr = std::lower_bound(data.begin(), data.end(),newWord);
if(insert_itr==data.end()||*insert_itr!=newWord){
data.insert(insert_itr, newWord);
}
else newWord.increaseCount();
}
return &newWord;
}
I am new to c++ so please excuse if silly errors. Thanks for any help in advance.
Also this code is giving me a vector size greater than expected. Any insights would be helpful :)