qsort, descripcion y ejemplo

Dependencies:   mbed

Committer:
sherckuith
Date:
Tue Apr 03 21:02:30 2012 +0000
Revision:
0:b011c638604b
qsort, descripcion y ejemplo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherckuith 0:b011c638604b 1 #include "mbed.h"
sherckuith 0:b011c638604b 2 /* qsort example */
sherckuith 0:b011c638604b 3 #include <stdio.h>
sherckuith 0:b011c638604b 4 #include <stdlib.h>
sherckuith 0:b011c638604b 5
sherckuith 0:b011c638604b 6 int values[] = { 40, 10, 100, 90, 20, 25 };
sherckuith 0:b011c638604b 7
sherckuith 0:b011c638604b 8 int compare (const void * a, const void * b)
sherckuith 0:b011c638604b 9 {
sherckuith 0:b011c638604b 10 return ( *(int*)a - *(int*)b );
sherckuith 0:b011c638604b 11 }
sherckuith 0:b011c638604b 12
sherckuith 0:b011c638604b 13 int main ()
sherckuith 0:b011c638604b 14 {
sherckuith 0:b011c638604b 15 int n;
sherckuith 0:b011c638604b 16 qsort (values, 6, sizeof(int), compare);
sherckuith 0:b011c638604b 17 for (n=0; n<6; n++)
sherckuith 0:b011c638604b 18 printf (": %d ",values[n]);
sherckuith 0:b011c638604b 19 return 0;
sherckuith 0:b011c638604b 20 }