⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsort.c

📁 C和指针非常好的一本书.里面的有许多代码可以借鉴.
💻 C
字号:
/*
** Demonstrates sorting an array of structures with qsort
*/
#include <stdlib.h>
#include <string.h>

typedef	struct	{
	char	key[ 10 ];	/* the sort key for the array */
	int	other_data;	/* data associated with the key */
} Record;

/*
** Comparison function: compares only the key value.
*/
int r_compare( void const *a, void const *b ){
	return strcmp( ((Record *)a)->key, ((Record *)b)->key );
}

int
main()
{
	Record	array[ 50 ];

	/*
	** Code that fills the array with 50 elements.
	*/

	qsort( array, 50, sizeof( Record ), r_compare );

	/*
	** Array is now sorted by the key field of the structures.
	*/

	return EXIT_SUCCESS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -