丁顺生简历以及照片:VC++ 中的排序

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 19:35:17
我用vc++6,想对存有cstring数组进行排序,vc中有没有现成的函数可以调用???

#include<algorithm>
#include<vector>
using namespace std;
bool sort_func(){};
int main(){
vector<char> vc(len);
sort(vc.begin,vc.end,sort_func);
}

#include <algorithm>
#include <string>
using namespace std;

bool func(const string &a,const string &b){
...//当a<b时return true否则false
}

int main()
{
string a[100];
sort(a,a+100);//对整个数组排序
sort(a,a+20);//对前十个string排序
sort(a,a+100,func);//实现自定义的排序,从小到大
}

使用STL的vector来存储这些string的指针
然后使用排序函数sort(iter_begin, iter_end, sort_func)来排序就可以了