#include <stdio.h>
#define N 10
typedef struct Node Node;
struct Node
{
int num;
int id;
};
Node node[N];
int cmp_int(const void *_p, const void *_q);
int main()
{
int i;
int a[N] = {1, 2, 3, 4, 5, 4, 6, 4, 7, 4};
for (i = 0; i < N; i++)
{
node[i].num = a[i];
node[i].id = i;
}
qsort(node, N, sizeof(Node), cmp_int);
for (i = 0; i < N; i++)
printf("id=%d, num=%d\n", node[i].id, node[i].num);
}
int cmp_int(const void *_p, const void *_q)
{
Node *p = (Node *)_p;
Node *q = (Node *)_q;
return p->num - q->num;
}
快速排序不是一个稳定的排序
最新推荐文章于 2024-03-05 12:28:16 发布