qsort_man.html
来自「Data Structure Ebook」· HTML 代码 · 共 81 行
HTML
81 行
<HTML><HEAD>
<TITLE>Data Structures and Algorithms - xx</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>Data Structures and Algorithms</H1>
<HR>
NAME<PRE>
qsort - quicker sort
</PRE>
SYNOPSIS<PRE>
qsort(base, nel, width, compar)
char *base;
int (*compar)();
</PRE>
DESCRIPTION<BR>
<TT>qsort()</TT> is an implementation of the quicker-sort algorithm.
It sorts a table of data in place.
<TT>base</TT> points to the element at the base of the table. <TT>nel</TT> is
the number of elements in the table. <TT>width</TT> is the size, in
bytes, of each element in the table. <TT>compar</TT> is the name of
the comparison function, which is called with two arguments
that point to the elements being compared. As the function
must return an integer less than, equal to, or greater than
zero, so must the first argument to be considered be less
than, equal to, or greater than the second.
<P>
NOTES<BR>
The pointer to the base of the table should be of type
pointer-to-element, and cast to type pointer-to-character.
The comparison function need not compare every byte, so
arbitrary data may be contained in the elements in addition
to the values being compared.
The order in the output of two items which compare as equal
is unpredictable.
<P>
SEE ALSO<BR>
sort(1V), bsearch(3), lsearch(3), string(3)
<P>
EXAMPLE<BR>
The following program sorts a simple array:
<PRE>
static int intcompare(i,j)
int *i, *j;
{
return(*i - *j);
}
main()
{
int a[10];
int i;
a[0] = 9;
a[1] = 8;
a[2] = 7;
a[3] = 6;
a[4] = 5;
a[5] = 4;
a[6] = 3;
a[7] = 2;
a[8] = 1;
a[9] = 0;
qsort(a,10,sizeof(int),intcompare)
for (i=0; i<10; i++) printf(" %d",a[i]);
printf("\n");
}
</PRE>
<BR>
<HR>
<A HREF="qsort.html" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/qsort.html">Back to Quicksort</A><BR>
<A HREF="ds_ToC.html" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/ds_ToC.html">Table of Contents</A>
<HR>
<SMALL>
© <A HREF=mailto:morris@ee.uwa.edu.au>John Morris</A>, 1996
</SMALL>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?