1、问题
读取一列整数,然后按升序排列它们,最后打印列表
2、代码实现
#include <stdio.h>
#include <stdlib.h>
/**
此函数根据你给的比较条件进行快速排序,通过指针移动实现排序
void qsort ( void * base, size_t num, size_t size, int ( * comparator ) ( const void *, const void * ) );
**/
int compare(void const *a, void const *b)
{
int const *pa = a;
int const *pb = b;
return *pa > *pb ? 1 : *pa < *pb ? -1 : 0;
}
int main()
{
int *array, values, i;
//输入多少个数据
puts("输入整数个数据");
if (scanf("%d", &values) != 1 || values <= 0)
{
puts("非法的数据");
goto error;
}
//分配内存
array = malloc(values * sizeof(int));
if (array == NULL)
{
goto error;
}
//读取数据
for (i = 0; i < values; ++i)
{
printf("?");
if (scanf("%d", array &