Ok, it's a little weird, but I'm basically trying to write a piece of code that would determine how many letters are different between two words, like cat and cot are off by one yet cat and dog are off by three.

So, I have a vector that contains all the three letter words I'm suppose to use, plus the word I'm suppose to compare them too. So, I made a new vector that using a struct that contains the string and the integer that stores the difference between the two of them words.

Is there a way I could sort that vector by the integer difference? If not, is there a way I could use the integer difference to go through the list and put the words in the right order?

I mean, there's obviously the option of going through the list multiple times until it's done. I was just curious is there was an easier way to do this.

Actually, I think I've got it. What I did is use the sort() comparison function, passed the struct, and had it compare by the difference there. Seems to work.

struct com
{  string data;
   int num;
};
bool com_num (com i,com j) { return (i.num<j.num); }

main()
{
vector <com> vec;
...
   sort (vec.begin(), vec.end(), com_num);
...
}
This question has already been answered. Start a new discussion instead.