Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

qksort.c File Reference

Go to the source code of this file.

Functions

int compare_int (const void *int1, const void *int2)
int partition (void *donnee, int taille_elt, int i, int k, int(*compare)(const void *cle1, const void *cle2))
int qksort (void *donnee, int nb_elts, int taille_elt, int i, int k, int(*compare)(const void *cle1, const void *cle2))
 Sort data using the QuickSort algorithm.

int extended_partition (void *donnee, int taille_elt, int i, int k, int(*compare)(const void *cle1, const void *cle2), int(*copy_data)(void *src, void *dest), int(*init_elem)(void *elm))
int extended_qksort (void *donnee, int nb_elts, int taille_elt, int i, int k, int(*compare)(const void *cle1, const void *cle2), int(*copy_data)(void *src, void *dest), int(*init_elem)(void *elm))
 Sort data using the QuickSort algorithm.


Detailed Description

This file implements the quick sort algorithm

Definition in file qksort.c.


Function Documentation

int extended_qksort void *    donnee,
int    nb_elts,
int    taille_elt,
int    i,
int    k,
int(*    compare)(const void *cle1, const void *cle2),
int(*    copy_data)(void *src, void *dest),
int(*    init_elem)(void *elm)
 

Sort data using the QuickSort algorithm.

Parameters:
donnee Pointer to the beginning of the array to sort.
nb_elts Number of elements to sort.
taille_elt Size in bytes of an element.
i i MUST BE set to 0.
k k MUST BE set to nb_elts - 1.
compare User defined function used to compare two elements of the array. If you want to sort according to increasing values, then the function compare() should return:
  • 1 if cle1 > cle2
  • 0 if cle1 == cle2
  • -1 if cle1 < cle2
If you want to sort according to decreasing values, then the function compare() should return:
  • 1 if cle1 < cle2
  • 0 if cle1 == cle2
  • -1 if cle1 > cle2
copy_data User defined function used to copy data. The function must take care of memory management. This function must return:
  • 0 upon successful completion.
  • 1 if an error occured.
init_elem User defined function used to initializen an element. This function must return:
  • 0 upon successful completion.
  • 1 if an error occured.
This function is called whenever a new element is allocated. Please note that you can specify a NULL pointer if no initialization is needed.
Returns:
Upon successful completion the function returns 0, otherwise it returns -1
Examples:
test_ext_sort.c.

Definition at line 293 of file qksort.c.

int qksort void *    donnee,
int    nb_elts,
int    taille_elt,
int    i,
int    k,
int(*    compare)(const void *cle1, const void *cle2)
 

Sort data using the QuickSort algorithm.

Parameters:
donnee Pointer to the beginning of the array to sort.
nb_elts Number of elements to sort.
taille_elt Size in bytes of an element.
i i MUST BE set to 0.
k k MUST BE set to nb_elts - 1.
compare User defined function used to compare two elements of the array. If you want to sort according to increasing values, then the function compare() should return:
  • 1 if cle1 > cle2
  • 0 if cle1 == cle2
  • -1 if cle1 < cle2
If you want to sort according to decreasing values, then the function compare() should return:
  • 1 if cle1 < cle2
  • 0 if cle1 == cle2
  • -1 if cle1 > cle2
Returns:
Upon successful completion the function returns 0, otherwise it returns -1
Examples:
test_sort.c.

Definition at line 127 of file qksort.c.


Generated on Thu Apr 3 16:23:46 2003 for Common_C_libraries by doxygen1.3-rc1