qsort.3 (604f1c416c128565923d63ab4cd98d1a7ced0cf4) | qsort.3 (0d2fabfc0439acfdb5d369feb2961e1b91faa39e) |
---|---|
1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the American National Standards Committee X3, on Information 6.\" Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without --- 18 unchanged lines hidden (view full) --- 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)qsort.3 8.1 (Berkeley) 6/4/93 33.\" $FreeBSD$ 34.\" | 1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the American National Standards Committee X3, on Information 6.\" Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without --- 18 unchanged lines hidden (view full) --- 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)qsort.3 8.1 (Berkeley) 6/4/93 33.\" $FreeBSD$ 34.\" |
35.Dd February 20, 2013 | 35.Dd January 14, 2020 |
36.Dt QSORT 3 37.Os 38.Sh NAME 39.Nm qsort , 40.Nm qsort_b , 41.Nm qsort_r , 42.Nm heapsort , 43.Nm heapsort_b , --- 49 unchanged lines hidden (view full) --- 93.Fc 94.Ft int 95.Fo mergesort_b 96.Fa "void *base" 97.Fa "size_t nmemb" 98.Fa "size_t size" 99.Fa "int \*[lp]^compar\*[rp]\*[lp]const void *, const void *\*[rp]" 100.Fc | 36.Dt QSORT 3 37.Os 38.Sh NAME 39.Nm qsort , 40.Nm qsort_b , 41.Nm qsort_r , 42.Nm heapsort , 43.Nm heapsort_b , --- 49 unchanged lines hidden (view full) --- 93.Fc 94.Ft int 95.Fo mergesort_b 96.Fa "void *base" 97.Fa "size_t nmemb" 98.Fa "size_t size" 99.Fa "int \*[lp]^compar\*[rp]\*[lp]const void *, const void *\*[rp]" 100.Fc |
101.Fd #define __STDC_WANT_LIB_EXT1__ 1 102.Ft errno_t 103.Fo qsort_s 104.Fa "void *base" 105.Fa "rsize_t nmemb" 106.Fa "rsize_t size" 107.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *, void *\*[rp]" 108.Fa "void *thunk" 109.Fc |
|
101.Sh DESCRIPTION 102The 103.Fn qsort 104function is a modified partition-exchange sort, or quicksort. 105The 106.Fn heapsort 107function is a modified selection sort. 108The --- 124 unchanged lines hidden (view full) --- 233Normally, 234.Fn qsort 235is faster than 236.Fn mergesort 237is faster than 238.Fn heapsort . 239Memory availability and pre-existing order in the data can make this 240untrue. | 110.Sh DESCRIPTION 111The 112.Fn qsort 113function is a modified partition-exchange sort, or quicksort. 114The 115.Fn heapsort 116function is a modified selection sort. 117The --- 124 unchanged lines hidden (view full) --- 242Normally, 243.Fn qsort 244is faster than 245.Fn mergesort 246is faster than 247.Fn heapsort . 248Memory availability and pre-existing order in the data can make this 249untrue. |
250.Pp 251The 252.Fn qsort_s 253function behaves the same as 254.Fn qsort_r , except that: 255.Bl -dash 256.It 257The order of arguments is different 258.It 259The order of arguments to 260.Fa compar 261is different 262.It 263if 264.Fa nmemb 265or 266.Fa size 267are greater than 268.Dv RSIZE_MAX , 269or 270.Fa nmemb 271is not zero and 272.Fa compar 273is NULL, then the runtime-constraint handler is called, and 274.Fn qsort_s 275returns an error. 276Note that the handler is called before 277.Fn qsort_s 278returns the error, and the handler function might not return. 279.El |
|
241.Sh RETURN VALUES 242The 243.Fn qsort 244and 245.Fn qsort_r 246functions 247return no value. | 280.Sh RETURN VALUES 281The 282.Fn qsort 283and 284.Fn qsort_r 285functions 286return no value. |
287The 288.Fn qsort_s 289function returns zero on success, non-zero on error. |
|
248.Pp 249.Rv -std heapsort mergesort 250.Sh EXAMPLES 251A sample program that sorts an array of 252.Vt int 253values in place using 254.Fn qsort , 255and then prints the sorted array to standard output is: --- 27 unchanged lines hidden (view full) --- 283 qsort(&int_array, array_size, sizeof(int_array[0]), int_compare); 284 for (k = 0; k < array_size; k++) 285 printf(" %d", int_array[k]); 286 puts(""); 287 return (EXIT_SUCCESS); 288} 289.Ed 290.Sh COMPATIBILITY | 290.Pp 291.Rv -std heapsort mergesort 292.Sh EXAMPLES 293A sample program that sorts an array of 294.Vt int 295values in place using 296.Fn qsort , 297and then prints the sorted array to standard output is: --- 27 unchanged lines hidden (view full) --- 325 qsort(&int_array, array_size, sizeof(int_array[0]), int_compare); 326 for (k = 0; k < array_size; k++) 327 printf(" %d", int_array[k]); 328 puts(""); 329 return (EXIT_SUCCESS); 330} 331.Ed 332.Sh COMPATIBILITY |
333The order of arguments for the comparison function used with 334.Fn qsort_r 335is different from the one used by 336.Fn qsort_s , 337and the GNU libc implementation of 338.Fn qsort_r . 339When porting software written for GNU libc, it is usually possible 340to replace 341.Fn qsort_r 342with 343.Fn qsort_s 344to work around this problem. 345.Pp |
|
291Previous versions of 292.Fn qsort 293did not permit the comparison routine itself to call 294.Fn qsort 3 . 295This is no longer true. 296.Sh ERRORS 297The 298.Fn heapsort --- 62 unchanged lines hidden (view full) --- 361.%D November\ 1993 362.Re 363.Sh STANDARDS 364The 365.Fn qsort 366function 367conforms to 368.St -isoC . | 346Previous versions of 347.Fn qsort 348did not permit the comparison routine itself to call 349.Fn qsort 3 . 350This is no longer true. 351.Sh ERRORS 352The 353.Fn heapsort --- 62 unchanged lines hidden (view full) --- 416.%D November\ 1993 417.Re 418.Sh STANDARDS 419The 420.Fn qsort 421function 422conforms to 423.St -isoC . |
424.Fn qsort_s 425conforms to 426.St -isoC-2011 427K.3.6.3.2. |
|
369.Sh HISTORY 370The variants of these functions that take blocks as arguments first appeared in 371Mac OS X. 372This implementation was created by David Chisnall. | 428.Sh HISTORY 429The variants of these functions that take blocks as arguments first appeared in 430Mac OS X. 431This implementation was created by David Chisnall. |