FreeBSD Bugzilla – Attachment 132009 Details for
Bug 176197
[PATCH] Add example to qsort.3
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 1.06 KB, created by
Fernando
on 2013-02-16 18:00:00 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
Fernando
Created:
2013-02-16 18:00:00 UTC
Size:
1.06 KB
patch
obsolete
>--- lib/libc/stdlib/qsort.3 2012-01-03 04:26:05.000000000 +0100 >+++ /home/fernape/Programming/FreeBSD/qsort_man/qsort.3 2013-02-16 18:42:44.000000000 +0100 >@@ -211,6 +211,52 @@ > did not permit the comparison routine itself to call > .Fn qsort 3 . > This is no longer true. >+.Sh EXAMPLES >+Sort an array of integers. >+.Bd -literal >+#include <stdio.h> >+#include <stdlib.h> >+#include <string.h> >+ >+/* >+ * Custom comparison function >+ */ >+static int >+str_compare(const void *p1, const void *p2) >+{ >+ >+ /* Cast and dereference */ >+ if (*(int *)p1 < *(int *)p2) >+ return (-1); >+ >+ if (*(int *)p1 > *(int *)p2) >+ return (1); >+ >+ return (0); >+ >+} >+ >+/* >+ * Sort an array of integers >+ */ >+int >+main(int argc, char **argv) >+{ >+ int i; >+ int int_array[] = {4, 5, 9, 3, 1, 7, 2, 8, 6}; >+ const int array_size = sizeof(int_array) / sizeof(int); >+ >+ /* Sort array */ >+ qsort(&int_array, array_size, sizeof(int), str_compare); >+ >+ /* Print out sorted array */ >+ for (i = 0; i < array_size; i++) { >+ printf("%d\n", int_array[i]); >+ } >+ >+ exit(EXIT_SUCCESS); >+} >+.Ed > .Sh ERRORS > The > .Fn heapsort
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 176197
: 132009 |
132010