=代码分享=

#include
#include
struct sb
{
char neme[20];
int b;
}d;

int Ba(const void* p, const void* q)
{
return (int)p - (int)q;
}

int Bb(const void* p, const void* q)
{
if ((float)p > (float)q)
return 1;
if ((float)p == (float)q)
return 0;
if ((float)p < (float)q)
return -1;
}
int Bc(const void* p, const void* q)
{
return (char)p - (char)q;
}

int Bd(const void* p, const void* q)
{
return strcmp(((struct sb*)p)->neme, ((struct sb*)q)->neme);
}

int main()
{
int a[10] = { 0,2,1,4,3,6,7,9,5,8 };
float b[5] = { 1.5,6.7,2.3,23.24,3.25 };
char c[10] = { “adshsdhs” };
struct sb d[5] = { {“zhang”,23},{“li”,34},{“wan”,16},{“ab”,80},{“xia”,34} };
int (p)(const void, const void*) = Bd;
qsort(d, 5,sizeof(struct sb), p);

int i = 0;
for (i = 0; i < 5; i++)
{
	printf("%s %d ", d[i].neme,d[i].b);
}

return 0;

}

你可能感兴趣的:(c语言)