欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

C語(yǔ)言快速排序函數(shù)用法(qsort)

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊: 次

本文實(shí)例為大家分享了C語(yǔ)言快排函數(shù)用法,供大家參考,具體內(nèi)容如下

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
  int id;
  char name[12];
  char sex;
};
int compare(const void* a,const void* b)//基本數(shù)據(jù)類(lèi)型排序
{
  return *(char*)a-*(char*)b;//從小到大
    //取值//強(qiáng)轉(zhuǎn)為相應(yīng)類(lèi)型的指針??!
}
int compare_struct(const void* a,const void* b)
{
  return (*(struct student*)a).id-((struct student*)b)->id;
         //注意優(yōu)先級(jí)誒!//否則報(bào)錯(cuò)在非結(jié)構(gòu)體中。。。
}
int compare_struct_duoji(const void* a,const void* b)//多級(jí)排序
{
  struct student student_a=*(struct student*)a;
  struct student student_b=*(struct student*)b;

  if(student_a.id==student_b.id)
  {
    return student_a.sex-student_b.sex;
  }
  else
  {
    return student_a.id-student_b.id;
  }
}
void main()
{
//*************char型*************
  char a[5]="hello";
  qsort(a,5,sizeof(a[0]),compare);
      //元素個(gè)數(shù)//元素大小//函數(shù)指針
  int i;
  for(i=0;i<5;i++)
      printf("%c ",a[i]);
  printf("\n");

//************struct型************
  struct student e[4]={{100,"chen",'m'},{100,"li",'f'}, \
             {70,"wang",'f'},{100,"zhang",'m'}};
  qsort(e,4,sizeof(e[1]),compare_struct_duoji);

  for(i=0;i<4;i++)
      printf("%d %s %c\n",e[i].id,e[i].name,e[i].sex);
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:在QT5中實(shí)現(xiàn)求兩個(gè)輸入值的和并輸出(實(shí)例)

欄    目:C語(yǔ)言

下一篇:基于C++的拼多多算法在線筆試題示例

本文標(biāo)題:C語(yǔ)言快速排序函數(shù)用法(qsort)

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/1247.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有