.TH shellsort() "" "" "General Function (libc)"
.PC "Sort arrays in memory"
\fBvoid shellsort(\fIdata\^\fB, \fIn\^\fB, \fIsize\^\fB, \fIcomp\^\fB)\fR
\fBchar *\fIdata\^\fB; int \fIn\^\fB, \fIsize\^\fB; int (*\fIcomp\^\fB)(\|)\^\fB;\fR
.PP
.II "Shell, D.L."
.B shellsort()
is a generalized algorithm for sorting arrays of data in memory,
using D. L. Shell's sorting method.
.B shellsort()
works with a sequential array of memory called
.IR data ,
which is divided into
.I n
parts of
.I size
bytes each.
In practice,
.I data
is usually an array of pointers or structures, and
.I size
is the
.B sizeof
the pointer or structure.
.PP
Each routine compares pairs of items and exchanges them as required.
The user-supplied routine to which
.I comp
points performs the comparison.
It is called repeatedly, as follows: 
.DM
	(*comp)(p1, p2)
	char *p1, *p2;
.DE
.PP
Here,
.I p1
and
.I p2
each point to a block of
.I size
bytes in the
.I data
array.
In practice, they are usually pointers to pointers or pointers
to structures.
The comparison routine must return a negative, zero, or positive result,
depending on whether
.I p1
is less than, equal to, or greater than
.IR p2 ,
respectively.
.SH Example
For an example of how to use this routine,
see the entry for
.BR string .
.SH "See Also"
.Xr "libc," libc
.Xr "qsort()" qsort
.br
\fIThe Art of Computer Programming, \fRvol. 3, pp. 84\fIff\fR, 114\fIff\fR
.SH Notes
For a discussion of how the
.B shellsort
algorithm differs from that used by
.BR qsort() ,
see the Lexicon entry for
.BR qsort() .
