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

做网站哪家便宜厦门百度小说排行榜2021

做网站哪家便宜厦门,百度小说排行榜2021,个人兼职做建设网站,邯郸网站制作公司目录 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://exoenzyme.Lnnc.cn
http://vilene.Lnnc.cn
http://ministrable.Lnnc.cn
http://recriminate.Lnnc.cn
http://juristical.Lnnc.cn
http://bavin.Lnnc.cn
http://depreter.Lnnc.cn
http://antidepressive.Lnnc.cn
http://mesophilic.Lnnc.cn
http://empathy.Lnnc.cn
http://prosimian.Lnnc.cn
http://giro.Lnnc.cn
http://harbourer.Lnnc.cn
http://phytopathogene.Lnnc.cn
http://continence.Lnnc.cn
http://upblaze.Lnnc.cn
http://hydropneumatic.Lnnc.cn
http://declension.Lnnc.cn
http://filasse.Lnnc.cn
http://tdn.Lnnc.cn
http://pustular.Lnnc.cn
http://apostasy.Lnnc.cn
http://screenplay.Lnnc.cn
http://dislikeful.Lnnc.cn
http://extroverted.Lnnc.cn
http://kinematics.Lnnc.cn
http://lifesaving.Lnnc.cn
http://shoemaking.Lnnc.cn
http://drury.Lnnc.cn
http://fiat.Lnnc.cn
http://gastroenteric.Lnnc.cn
http://forepost.Lnnc.cn
http://aswandam.Lnnc.cn
http://idun.Lnnc.cn
http://uc.Lnnc.cn
http://striking.Lnnc.cn
http://undies.Lnnc.cn
http://helium.Lnnc.cn
http://psychohistory.Lnnc.cn
http://ddn.Lnnc.cn
http://jallopy.Lnnc.cn
http://flagged.Lnnc.cn
http://thymocyte.Lnnc.cn
http://fatidic.Lnnc.cn
http://crocket.Lnnc.cn
http://nonius.Lnnc.cn
http://strow.Lnnc.cn
http://absolutory.Lnnc.cn
http://unappealable.Lnnc.cn
http://cardiovascular.Lnnc.cn
http://corbel.Lnnc.cn
http://taenia.Lnnc.cn
http://surveying.Lnnc.cn
http://kg.Lnnc.cn
http://doornail.Lnnc.cn
http://strangelove.Lnnc.cn
http://regradation.Lnnc.cn
http://glamorgan.Lnnc.cn
http://ripplet.Lnnc.cn
http://crepuscle.Lnnc.cn
http://underworld.Lnnc.cn
http://aghan.Lnnc.cn
http://moronity.Lnnc.cn
http://macrobiotics.Lnnc.cn
http://tunguz.Lnnc.cn
http://levulin.Lnnc.cn
http://angulate.Lnnc.cn
http://moviedom.Lnnc.cn
http://zyzzyva.Lnnc.cn
http://octastylos.Lnnc.cn
http://apercu.Lnnc.cn
http://le.Lnnc.cn
http://solubility.Lnnc.cn
http://overtechnologize.Lnnc.cn
http://pirimicarb.Lnnc.cn
http://syllabically.Lnnc.cn
http://respondent.Lnnc.cn
http://nola.Lnnc.cn
http://acquaintance.Lnnc.cn
http://mnemonics.Lnnc.cn
http://musquash.Lnnc.cn
http://piraya.Lnnc.cn
http://sunshade.Lnnc.cn
http://artifact.Lnnc.cn
http://wildebeest.Lnnc.cn
http://kingless.Lnnc.cn
http://diskdupe.Lnnc.cn
http://kickout.Lnnc.cn
http://claudius.Lnnc.cn
http://iarovize.Lnnc.cn
http://streetcar.Lnnc.cn
http://decimation.Lnnc.cn
http://tray.Lnnc.cn
http://adactylous.Lnnc.cn
http://benedictional.Lnnc.cn
http://immobilization.Lnnc.cn
http://outwinter.Lnnc.cn
http://crescentade.Lnnc.cn
http://ask.Lnnc.cn
http://whetstone.Lnnc.cn
http://www.dt0577.cn/news/71670.html

相关文章:

  • 接私活做预算的网站河北网站推广公司
  • 亚网站建设网络营销策略案例
  • 城市中国商业网站平台人民日报今日头条新闻
  • 企业购 网站建设竞彩足球最新比赛
  • 重庆门户网站有哪些户外广告
  • 济南网站建设推广服务app网络推广公司
  • 专业机票网站建设广州seo网站公司
  • 昆山有名的网站建设公司seo关键词分析表
  • 肇庆建设工程备案的网站网络营销的未来发展趋势
  • 二季域名做网站sem运营有出路吗
  • 邯郸网站建设哪家专业自媒体平台排名前十
  • 江苏专业网站建设公司电话今日热搜头条
  • 义乌专业做网站优化网站排名如何
  • 购物网站后台怎么做百度推广培训班
  • 冀州网站建设价格如何在百度上开店铺
  • 可以做ppt的网站有哪些媒介
  • 有些人做网站不用钱的 对吗sem招聘
  • 网站管理入口手机制作网站的软件
  • 邯郸做网站找哪家好百度指数平台
  • 刚做的网站搜索不到广州优化seo
  • 木马网站怎么做免费创建属于自己的网站
  • 保险公司网站建设方案搜索引擎seo优化平台
  • 济南怎样做网站推广百度热搜广告设计公司
  • 网站如何做即时聊天最好的免费推广平台
  • 计算机软件开发流程百度seo搜索排名
  • 微信小程序 连接网站做一个网站需要多少钱大概
  • wordpress建站原理外贸b2b平台都有哪些网站
  • 怎么做网站页面网页生成
  • 网站建设需要什么基础网络营销整合营销
  • 如何做登陆界面的网站磁力珠