Previous: bnd_bsearch, Up: Lists


11.2 partition

partition a list about an object

Synopsis

     #include <suplib/lists.h>
     
     
     
void *partition( void *obj, void *p_obj, void *work, size_t s_obj, unsigned long n_obj, int (*obj_comp)(const void *obj1,const void *obj2) );

Parameters

void *obj
list of objects to partition
void *p_obj
object about which to partition list. need not be in the list
void *work
work area with size 2 * s_obj
size_t s_obj
size of an object in bytes
unsigned long n_obj
number of objects in list
int (*obj_comp)(const void *obj1,const void *obj2)
function which compares two objects and returns < 1, 0, > 1, depending if the first object is less than, equal to, or greater than the second

Description

partitions the list obj[0 ... n] into two sub-lists obj[0 ... q] and obj[q+1 ... n], such that obj[i] (0 <= i <= q) <= pobj <= obj[j] (q < j <= n) where pobj is a supplied "pivot" point. returns the top object in the first sub-list, i.e. obj[q]. pobj need not be in the list. in this case, if no object is less than pobj, NULL is returned.

References

See "Introduction to Algorithms", T.H.Kormen, C.E.Leiserson, and R.L. Rivest sec. 8.1, p.154.

Author

Diab Jerius