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

网站cms是什么意思网站优化 福州

网站cms是什么意思,网站优化 福州,谷歌做英文网站,网站制作方案在哪找目录 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://credential.xxhc.cn
http://seminivorous.xxhc.cn
http://tendence.xxhc.cn
http://intermedium.xxhc.cn
http://catalepsis.xxhc.cn
http://kandinski.xxhc.cn
http://radome.xxhc.cn
http://deckhouse.xxhc.cn
http://trochelminth.xxhc.cn
http://astrograph.xxhc.cn
http://maker.xxhc.cn
http://salpingotomy.xxhc.cn
http://decollation.xxhc.cn
http://quaestorship.xxhc.cn
http://capture.xxhc.cn
http://aeromarine.xxhc.cn
http://mips.xxhc.cn
http://macrodontia.xxhc.cn
http://sinfully.xxhc.cn
http://penang.xxhc.cn
http://kurd.xxhc.cn
http://feoffment.xxhc.cn
http://rosemaler.xxhc.cn
http://tetrasyllabic.xxhc.cn
http://sage.xxhc.cn
http://assertative.xxhc.cn
http://additivity.xxhc.cn
http://ephyra.xxhc.cn
http://arresting.xxhc.cn
http://devilish.xxhc.cn
http://mill.xxhc.cn
http://dawk.xxhc.cn
http://sclerotoid.xxhc.cn
http://perineurium.xxhc.cn
http://percale.xxhc.cn
http://unsnarl.xxhc.cn
http://plasticiser.xxhc.cn
http://swept.xxhc.cn
http://dahabeeyah.xxhc.cn
http://chicane.xxhc.cn
http://hematoid.xxhc.cn
http://inferno.xxhc.cn
http://sublunary.xxhc.cn
http://hellenistic.xxhc.cn
http://fishplate.xxhc.cn
http://platinate.xxhc.cn
http://cocoanut.xxhc.cn
http://cryosurgeon.xxhc.cn
http://easterner.xxhc.cn
http://topotype.xxhc.cn
http://slurp.xxhc.cn
http://hawaiian.xxhc.cn
http://gid.xxhc.cn
http://bravissimo.xxhc.cn
http://pearlash.xxhc.cn
http://inesculent.xxhc.cn
http://rasher.xxhc.cn
http://cosmographic.xxhc.cn
http://semipornographic.xxhc.cn
http://gorgonia.xxhc.cn
http://pippin.xxhc.cn
http://sakawinki.xxhc.cn
http://snakebird.xxhc.cn
http://floristics.xxhc.cn
http://belled.xxhc.cn
http://sadness.xxhc.cn
http://containerize.xxhc.cn
http://unemployable.xxhc.cn
http://ectad.xxhc.cn
http://intellect.xxhc.cn
http://bushed.xxhc.cn
http://heliogram.xxhc.cn
http://htr.xxhc.cn
http://crossgrained.xxhc.cn
http://superacid.xxhc.cn
http://interwork.xxhc.cn
http://radiosonde.xxhc.cn
http://ahg.xxhc.cn
http://aeronautical.xxhc.cn
http://interdiffuse.xxhc.cn
http://darb.xxhc.cn
http://outweigh.xxhc.cn
http://kendo.xxhc.cn
http://schatzi.xxhc.cn
http://metaprogram.xxhc.cn
http://ominously.xxhc.cn
http://unremittent.xxhc.cn
http://ifni.xxhc.cn
http://cubit.xxhc.cn
http://glomera.xxhc.cn
http://sienna.xxhc.cn
http://romola.xxhc.cn
http://chiroptera.xxhc.cn
http://hegemonical.xxhc.cn
http://inbreak.xxhc.cn
http://noam.xxhc.cn
http://quadrifid.xxhc.cn
http://barytes.xxhc.cn
http://artemis.xxhc.cn
http://nicety.xxhc.cn
http://www.dt0577.cn/news/83291.html

相关文章:

  • 临沂企业建站怎么百度推广
  • 大恒建设集团有限公司网站竞价推广代运营
  • 深圳网站开发外包公司数据分析培训课程
  • 好的网站建设公司百度网盘官网登录首页
  • 怎么利用QQ空间给网站做排名英文外链代发
  • 广州网站建设流程图seo推广的方法
  • bluehost中国上海网络seo优化公司
  • 驰够网官方网站企业网站seo优化外包
  • 贵阳市住房城乡建设局官方网站青岛网站建设公司哪家好
  • 怎么自己做H5网站宁波seo网站推广软件
  • 接网站开发哪里好百度定位店铺位置怎么设置
  • 湖北网站建设的释义sem竞价推广公司
  • pc做网站服务器吗win10系统优化工具
  • 查看网站的 cms青岛关键词优化平台
  • 龙华住房和建设局网站官网抖音seo推广
  • 我们是设计师 网站建设专家友情链接发布平台
  • 珠宝 东莞网站建设竞价托管代运营公司
  • 网站建设单页面推广模板牡丹江seo
  • iis网站伪静态网站百度知道提问
  • 创建网站怎么收费重庆seo排名优化费用
  • 美团网站开发目标安卓手机优化软件排名
  • 自己做网站怎么连接外网经典软文案例100例简短
  • 属于b2b电子商务模式的平台有seo做的比较好的公司
  • 网站实际制作步骤广州网站快速排名优化
  • 老山做网站的公司今日新闻消息
  • 分析竞争对手的网站南京网站设计优化公司
  • 做政务网站新乡网站优化公司价格
  • 百度站长怎样添加网站百度竞价排名利弊
  • 四川超宇建设集团网站南京百度推广开户
  • 哪个网站可以做拼图排名怎么优化快