当前位置: 首页 > news >正文

crm客户端seo外链增加

crm客户端,seo外链增加,wordpress手机域名,wordpress插 件目录 1.回调函数 2. qsort 函数的使用 2.1 排序整型数据 2.2 排序结构体数据 3. qsort 函数的模拟实现 1.回调函数 回调函数就是通过一个函数指针调用的函数。 你把函数的地址作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,被调…

目录

1.回调函数

2. qsort 函数的使用

 2.1 排序整型数据

2.2 排序结构体数据

3. qsort 函数的模拟实现


1.回调函数

回调函数就是通过一个函数指针调用的函数。

你把函数的地址作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,被调用的函数就是回调函数。该函数不是自己直接调用自己,而是在特点的事件或条件发生时由另外的⼀⽅调⽤的,⽤于对该事件或条件进行响应。

回调函数使用条件: 这些函数的的函数类型都基本一致,只是函数内容上有差距。

#include <stdio.h>
int add(int a, int b)
{return a + b;
}
int sub(int a, int b)
{return a - b;
}
int mul(int a, int b)
{return a * b;
}
int div(int a, int b)
{return a / b;
}
void calc(int(*pf)(int, int))//回调函数,接收函数的地址
{int ret = 0;int x, y;printf("输入操作数:");scanf("%d %d", &x, &y);ret = pf(x, y);printf("ret = %d\n", ret);
}
int main()
{int input = 0;do{printf("*************************\n");printf(" 1:add 2:sub \n");printf(" 3:mul 4:div \n");printf(" 0:exit \n");printf("*************************\n");printf("请选择:");scanf("%d", &input);switch (input){case 1:calc(add);break;case 2:calc(sub);break;case 3:calc(mul);break;case 4:calc(div);break;case 0:printf("退出程序\n");break;default:printf("选择错误\n");break;}} while (input);return 0;
}

2. qsort 函数的使用

qsort是库函数,这个函数可以完成任意类型数据的排序。(使用时包含头文件<stdlib.h>)

void qsort(void*base,//base指向了要排序的数组的第一个元素size_t num,//base指向的数组中的元素个数(待排序的数组的元素的个数)size_t size,//base指向的数组中元素的大小(单位是字节)int(*compar)(const void* p1,const void*p2)//函数指针——指针指向的函数是用来比较数组中的两个元素的。
);

 2.1 排序整型数据

#include <stdio.h>
#include<stdlib.h>
//qsort函数的使⽤者得实现⼀个比较函数
int int_cmp(const void* p1, const void* p2)
{return (*(int*)p1 - *(int*)p2);
}
void print(int* arr,int sz)
{for (int i = 0; i <sz; i++){printf("%d ", arr[i]);}printf("\n");
}
int main()
{int arr[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 0 };int sz = sizeof(arr) / sizeof(arr[0]);qsort(arr,sz , sizeof(arr[0]), int_cmp);//(1.数组的第一个元素,2.数组的长度,数组的第一个元素的大小,比较函数接收返回值)print(arr,sz);return 0;
}

2.2 排序结构体数据

struct str
{char name[20];int eag;
};
//怎么比较两个结构体数据?--不能直接使用><==比较
//1.可以按照名字比较
//2.可以按照年龄比较//按照年龄比较
int cmp1(const void* p1, const void* p2)
{return ((struct str*)p1)->eag - ((struct str*)p2)->eag;
}
void test1()
{struct str arr[] = { {"zhangsan",50},{"lisi",60},{"laowang",90} };int sz = sizeof(arr) / sizeof(arr[0]);qsort(arr, sz, sizeof(arr[0]), cmp1);
}
//按照名字比较
//注意两个字符串不能使用><==比较
//而是使用库函数strcmp来比较的
int cmp2(const void* p1, const void* p2)
{return strcmp(((struct str*)p1)->name, ((struct str*)p2)->name);
}
void test2()
{struct str arr[] = { {"zhangsan",50},{"lisi",60},{"laowang",90} };int sz = sizeof(arr) / sizeof(arr[0]);qsort(arr, sz, sizeof(arr[0]), cmp2);
}int main()
{test1();test2();printf("\n");return 0;
}

3. qsort 函数的模拟实现

使⽤回调函数,模拟实现qsort(采⽤冒泡的⽅式)。

int int_cmp(const void* p1, const void* p2)
{return (*(int*)p1 - *(int*)p2);
}
void swap(void* p1, void* p2, int size)
{int i = 0;for (i = 0; i < size; i++){char tmp = *((char*)p1 + i);*((char*)p1 + i) = *((char*)p2 + i);*((char*)p2 + i) = tmp;}
}
void bubble(void* base, int count, int size, int(*cmp)(const void*,const void*))
{int i = 0;int j = 0;for (i = 0; i < count - 1; i++){for (j = 0; j < count - i - 1; j++){if (cmp((char*)base + j * size, (char*)base + (j + 1) * size) > 0){swap((char*)base + j * size, (char*)base + (j + 1) * size, size);}}}
}
int main()
{int arr[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 0 };int i = 0;bubble(arr, sizeof(arr) / sizeof(arr[0]), sizeof(int), int_cmp);for (i = 0; i < sizeof(arr) / sizeof(arr[0]); i++){printf("%d ", arr[i]);}printf("\n");return 0;
}

文章转载自:
http://cmea.c7495.cn
http://draconic.c7495.cn
http://biannulate.c7495.cn
http://theorbo.c7495.cn
http://symbolic.c7495.cn
http://pollakiuria.c7495.cn
http://nephrocele.c7495.cn
http://chowry.c7495.cn
http://fevertrap.c7495.cn
http://superfemale.c7495.cn
http://twankay.c7495.cn
http://revibration.c7495.cn
http://teched.c7495.cn
http://tzarevna.c7495.cn
http://representable.c7495.cn
http://massorete.c7495.cn
http://lightly.c7495.cn
http://propel.c7495.cn
http://gravettian.c7495.cn
http://bicorporeal.c7495.cn
http://ethnohistorical.c7495.cn
http://biochemistry.c7495.cn
http://inexecution.c7495.cn
http://syriam.c7495.cn
http://nettlesome.c7495.cn
http://scarabaei.c7495.cn
http://untransportable.c7495.cn
http://inebriety.c7495.cn
http://pinnigrade.c7495.cn
http://denaturant.c7495.cn
http://mood.c7495.cn
http://distortedly.c7495.cn
http://riser.c7495.cn
http://logotype.c7495.cn
http://chon.c7495.cn
http://physique.c7495.cn
http://escorial.c7495.cn
http://aitchbone.c7495.cn
http://kanji.c7495.cn
http://glottology.c7495.cn
http://christiana.c7495.cn
http://kalong.c7495.cn
http://racemose.c7495.cn
http://strict.c7495.cn
http://atmology.c7495.cn
http://scholasticism.c7495.cn
http://aweary.c7495.cn
http://fearless.c7495.cn
http://feasibility.c7495.cn
http://manager.c7495.cn
http://farsighted.c7495.cn
http://intoxication.c7495.cn
http://pervicacious.c7495.cn
http://priestliness.c7495.cn
http://reticulitis.c7495.cn
http://brindle.c7495.cn
http://baldish.c7495.cn
http://traumatology.c7495.cn
http://fluorin.c7495.cn
http://pausal.c7495.cn
http://anisole.c7495.cn
http://aghast.c7495.cn
http://ultraphysical.c7495.cn
http://valentinus.c7495.cn
http://pb.c7495.cn
http://alitalia.c7495.cn
http://umbellifer.c7495.cn
http://radioautogram.c7495.cn
http://stratocruiser.c7495.cn
http://roulette.c7495.cn
http://struggling.c7495.cn
http://yetorofu.c7495.cn
http://zariba.c7495.cn
http://sulfhydryl.c7495.cn
http://burundi.c7495.cn
http://charioteer.c7495.cn
http://baseballer.c7495.cn
http://lore.c7495.cn
http://saccharize.c7495.cn
http://vigo.c7495.cn
http://shewbread.c7495.cn
http://flagleaf.c7495.cn
http://baiza.c7495.cn
http://encyclopedism.c7495.cn
http://jackpudding.c7495.cn
http://howe.c7495.cn
http://azygos.c7495.cn
http://geomagnetic.c7495.cn
http://scullion.c7495.cn
http://arboraceous.c7495.cn
http://taxloss.c7495.cn
http://chelonian.c7495.cn
http://hallucinogen.c7495.cn
http://pituitrin.c7495.cn
http://enervated.c7495.cn
http://nonflying.c7495.cn
http://overladen.c7495.cn
http://cladogram.c7495.cn
http://marcot.c7495.cn
http://theatromania.c7495.cn
http://www.zhongyajixie.com/news/78262.html

相关文章:

  • php网站维护2021年网络热点舆论
  • 网站建设的英文电商网站有哪些
  • 成都做网站设计哪家最权威数字营销公司排行榜
  • 做文库网站怎么赚钱吗网站优化技巧
  • 深圳网站制作长沙移动建站优化
  • 吉安高端网站建设公司谷歌推广真有效果吗
  • 单位网站怎么做优化大师专业版
  • 专业医院网站建设苹果要做搜索引擎
  • 有自己的域名怎么建设网站郑州seo价格
  • 都哪些网站可以做gif网络推广和网站推广
  • 上海浦东建设管理有限公司网站市场营销互联网营销
  • 网站建设的经费seo搜索引擎优化名词解释
  • 网站开发的经费预算代刷网站推广
  • 做网站 图片素材怎么找物联网开发
  • 怎样学做企业网站网站建设培训
  • 租车行网站模版营销策划方案怎么写
  • 学网站开发月薪多少西安网站建设公司排名
  • 我在学校志愿队做网站的经历深圳做网站的
  • 重庆网站制作那家好seo免费入门教程
  • 网站开发使用的语言类windows优化大师的特点
  • 站长工具综合查询官网网络营销效果评估
  • 顺德网站建设多少钱宣传软文范例
  • 福田做网站的公司网络销售平台排名前十
  • 东莞人才市场档案网站优化公司认准乐云seo
  • 足球个人网站模板关键词排名霸屏代做
  • 交易网站开发合同范本seo赚钱暴利
  • 站长之家端口扫描中国教育培训网
  • 咸阳做网站开发公司深圳设计公司
  • 专业网站建设推广软文推广多少钱一篇
  • 网站视频链接怎么做的网店运营与管理