您的位置:首页 > 其它

STL中List 的sort 比较 用法示例

2010-12-13 15:17 495 查看
#include <string>
#include <list>
#include <algorithm>
#include <iostream>
using namespace std;
bool op(string str1, string str2)
{
return str1.length() < str2.length();
}
int main(int argc, char* argv[])
{
list <string> list_story;
list_story.push_back("the");
list_story.push_back("quick");
list_story.push_back("red");
list_story.push_back("fox");
list_story.push_back("jumps");
list_story.push_back("over");
list_story.push_back("the");
list_story.push_back("slow");
list_story.push_back("red");
list_story.push_back("turtle");
list_story.sort(op);
for(list<string>::iterator i = list_story.begin(); i != list_story.end(); i++)
{
cout << *i << endl;
}
}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  list string iterator include