SW006014 Microchip Technology, SW006014 Datasheet - Page 110

C COMPILER MPLAB FOR PIC24 MCU

SW006014

Manufacturer Part Number
SW006014
Description
C COMPILER MPLAB FOR PIC24 MCU
Manufacturer
Microchip Technology
Type
MPLAB® C Compilerr
Series
PIC24r
Datasheet

Specifications of SW006014

Supported Families
PIC24
Core Architecture
PIC
Kit Contents
Software And Docs
Mcu Supported Families
PIC24
Tool Function
Compiler
Tool Type
Compiler
Processor Series
PIC24
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
PIC24
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
DS51456E-page 106
qsort
Description:
Include:
Prototype:
Arguments:
Remarks:
Example:
Performs a quick sort.
<stdlib.h>
void qsort(void *base, size_t nelem, size_t size,
base
nelem
size
cmp
e1
e2
qsort overwrites the array with the sorted array. The comparison func-
tion is supplied by the user. In the following example, the list is sorted
according to the comparison function. This comp uses ascending order.
#include <stdlib.h> /* for qsort
#include <stdio.h>
#define NUM 7
int comp(const void *e1, const void *e2);
int main(void)
{
}
int comp(const void *e1, const void *e2)
{
}
Output:
Unsorted List: 35
Sorted List:
int (*cmp)(const void *e1, const void *e2));
int list[NUM] = {35, 47, 63, 25, 93, 16, 52};
int x;
printf("Unsorted List: ");
for (x = 0; x < NUM; x++)
qsort(list, NUM, sizeof(int), comp);
printf("\n");
printf("Sorted List:
for (x = 0; x < NUM; x++)
const int * a1 = e1;
const int * a2 = e2;
if (*a1 < *a2)
else if (*a1 == *a2)
else
printf("%d
printf("%d
return -1;
return 0;
return 1;
pointer to the start of the array
number of elements
size of the elements
pointer to the comparison function
pointer to the key for the search
pointer to the element being compared with the key
16
", list[x]);
", list[x]);
47
25
/* for printf */
63
35
");
25
47
© 2008 Microchip Technology Inc.
93
52
*/
16
63
52
93

Related parts for SW006014