结构体中用字符串排序的sort自定义函数和 结构体的操作

来源:互联网 发布:axure mac汉化教程 编辑:程序博客网 时间:2024/04/20 02:04

此函数为快速排序中自定义函数的写法,这是对结构体中的字符串来排序:

sort(&str2[0],&str2[0]+t,cmp);bool cmp(const Person a,const Person b){    return strcmp(a.name,b.name)<0;}

结构体变量可以整体初始化,但是不能整体赋初值。
结构体可以两个之间赋值:

struct test{      int data;      int id;};    test test1 = {90, 200902};     test test2;     test2 = test1;
0 0