文章来源: http://bbs.csdn.net/topics/330037235
#include <string>
#include <list>
#include <iostream>
using
namespace
std;
bool
cmp(
const
string& s1,
const
string& s2);
int
main()
{
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"
);
for
(list<string>::iterator iter = list_story.begin();iter != list_story.end();iter++)
{
cout<<*iter<<endl;
}
cout<<
"sort after"
<<endl;
list_story.sort(cmp);
for
(list<string>::iterator iter = list_story.begin();iter != list_story.end();iter++)
{
cout<<*iter<<endl;
}
system
(
"pause"
);
}
bool
cmp(
const
string& s1,
const
string& s2)
{
return
s1.length() < s2.length();
}