X-Git-Url: http://git.csclub.uwaterloo.ca/?p=kopensolaris-gnu%2Fglibc.git;a=blobdiff_plain;f=manual%2Fsearch.texi;h=abb93bb5a88e134b71c8ab82185b41fb188d34ab;hp=b328a39be0eb257ec9fe3bd0bdc9b37b05b66c43;hb=b2e3fff13c30ec745400c4b57ea87f9d5d848db7;hpb=28c9c07253fec10a54189b6f97f52b11ef25d50c diff --git a/manual/search.texi b/manual/search.texi index b328a39be0..abb93bb5a8 100644 --- a/manual/search.texi +++ b/manual/search.texi @@ -1,5 +1,5 @@ -@node Searching and Sorting, Pattern Matching, Locales, Top -@chapter Searching and Sorting +@node Searching and Sorting, Pattern Matching, Message Translation, Top +@chapter Searching and Sorting This chapter describes functions for searching and sorting arrays of arbitrary objects. You pass the appropriate comparison function to be @@ -10,7 +10,7 @@ and the total number of elements. * Comparison Functions:: Defining how to compare two objects. Since the sort and search facilities are general, you have to specify the - ordering. + ordering. * Array Search Function:: The @code{bsearch} function. * Array Sort Function:: The @code{qsort} function. * Search/Sort Example:: An example program. @@ -64,11 +64,11 @@ the header file @file{stdlib.h}. @pindex stdlib.h @comment stdlib.h -@comment ANSI +@comment ISO @deftypefun {void *} bsearch (const void *@var{key}, const void *@var{array}, size_t @var{count}, size_t @var{size}, comparison_fn_t @var{compare}) The @code{bsearch} function searches the sorted array @var{array} for an object that is equivalent to @var{key}. The array contains @var{count} elements, -each of which is of size @var{size} bytes. +each of which is of size @var{size} bytes. The @var{compare} function is used to perform the comparison. This function is called with two pointer arguments and should return an @@ -97,7 +97,7 @@ To sort an array using an arbitrary comparison function, use the @pindex stdlib.h @comment stdlib.h -@comment ANSI +@comment ISO @deftypefun void qsort (void *@var{array}, size_t @var{count}, size_t @var{size}, comparison_fn_t @var{compare}) The @var{qsort} function sorts the array @var{array}. The array contains @var{count} elements, each of which is of size @var{size}. @@ -118,6 +118,8 @@ respects. If you want the effect of a stable sort, you can get this result by writing the comparison function so that, lacking other reason distinguish between two elements, it compares them by their addresses. +Note that doing this may make the sorting algorithm less efficient, so +do it only if necessary. Here is a simple example of sorting an array of doubles in numerical order, using the comparison function defined above (@pxref{Comparison @@ -189,5 +191,3 @@ Kermit, the frog Gonzo, the whatever Couldn't find Janice. @end smallexample - -