/******************************
*	poin_fct.c
*	19.03.2002
******************************/

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

#define	POCET 10000
#define	RND_START 1234

int float_sort (const float *a, const float *b)
{
 return (*a - *b);	
} 

void test (float *p, unsigned int pocet)
/* otestuje zda dane pole je setrideno vzestupne */
{
 int chyba = 0;
 for (; !chyba && --pocet > 0; p++)
   if (*p > *(p+1))
     chyba=1;
 puts ((chyba) ? "\npole neni setrideno\n" : "\npole je setrideno\n");
} 

void vypln(float *p, int pocet)
/* vypni pole dane adresou a pocte prvku, nahodnymi cisly pomoci generatoru nahodnych cisel */
{
 srand(RND_START);
 while (pocet-- > 0)
    *p++ = (float) rand();
} 

int main (void)
{
 static float pole [POCET];

 vypln (pole, POCET);
 clock(); /* zacatek pocitani casu */
 qsort(pole, POCET, sizeof(*pole), (int (*) (const void *, const void *)) float_sort);
 /* uplynuly cas v ticich preveden na sekundy */
 printf ("Trideni qsort trvalo %.2fs\n", ((float) clock()) / CLOCKS_PER_SEC);  
 test (pole, POCET);

 return 0;
}