开发者

Sorting by last names with the same first letter

Im trying to write a code that takes a vector of full names, and then sorts by the last name only. To do this im using a selection sort and isolating the last name of each vector entry before comparing them to each other using .co开发者_如何转开发mpare(). This worked for most names, but started to give me problems when there were 2+ last names with the same first letter as each other. How can I change my comparison to sort precisely based on each subsequent letter of a last name?

I tried using this bit of code to compare the last names:

if(iLastName.compare(minLastName) < 0) {
            min = i;   
         }

however, when two people have last names such as 'Mahon' and 'McFadden', the code isnt precise enough with its sorting and allows them to be in any order (depending on where they are in the original vector).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜