/*e19 編程。使用標準庫函數qsort(),對各類數組進行排序。函數原型爲:
void qsort((void*)a,int size,int width,int(*fcmp)(const void*,const void*));
(1) 對整數數組排序。要求按每個元素各位數字之和,升序排列。
(12,32,42,51,8,16,51,21,19,9)
(2) 對浮點數組排序。升序排列。
(32.1,456.87,332.67,442.0,98.12,451.79,340.12,54.55,99.87,72.5)
(3) 對字符串數組排序。
(enter,number,size,begin,of,cat,cap,program,certain,a)
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
int cmpint(const void *a,const void *b)
{
return *(int*)a-*(int*)b;
}
int cmpfloat(const void *a,const void *b)
{
return *(double*)a-*(double*)b;
}
int cmpstring(const void *a,const void *b)
{
return strcmp((char*)a,(char*)b);
}
void main()
{
int i[]={12,32,42,51,8,16,51,21,19,9};
double f[]={32.1,456.87,332.67,442.0,98.12,451.79,340.12,54.55,99.87,72.5};
char s[][10]={"enter","number","size","begin","of","cat","cap","program","certain","a"};
qsort(i,10,sizeof(i[0]),cmpint);
qsort(f,10,sizeof(f[0]),cmpfloat);
qsort(s,10,10,cmpstring);
for(int index=0;index<10;index++)
cout<<i[index]<<'/t';
cout<<endl;
for(index=0;index<10;index++)
cout<<f[index]<<'/t';
cout<<endl;
for(index=0;index<10;index++)
cout<<s[index]<<'/t';
cout<<endl;
}
關於標準庫函數qsort()的使用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
男人如何持久?重現男人本色需從細節入手
SteveSapp9
2022-06-23 11:21:40
aesrdvbrtgnfycjumghki,jokl
bglmqecwg
2022-06-20 03:42:04
Aurelien Tchouameni will try to break the curse of the No 18 shirt inherits Bale number
dogj6613
2022-06-19 16:35:29
Regarder film 4K HD
firdauskomarove
2022-06-19 12:36:40
性愛中怎樣才能持久?多用這些小技巧
SteveSapp9
2022-06-18 15:52:27
Ver Pelicula HD 4K
firdauskomarove
2022-06-18 13:35:49
必利吉吃法,必利吉哪裏買
LouisRodgers5773
2022-06-17 11:18:38
Guarda HD Ultra 4K
firdauskomarove
2022-06-17 08:49:35
dfgshfdg
tenoxop591
2022-06-16 19:51:46
這三個性愛技巧 是所有男人都必須掌握的
SteveSapp9
2022-06-16 15:29:47
HerpaGreens Review - You Read its Ingredients Benefits and Side Effects?
ophnjhas
2022-06-15 17:13:35
adagerb sfvgaerg erag
edsa46457
2022-06-15 02:28:31
男人性功能障礙有何表現
LouisRodgers5773
2022-06-14 12:29:07
DBI\DPI\DSI簡介 (紀錄)
cheweiwu1986
2022-06-14 11:30:42
Biotech Ingredients Market Rising Demand and Future Scope till by 2030
chhidami.a.msg
2022-06-13 20:59:00