OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[linuxjm/LDP_man-pages.git] / release / man3 / qsort.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\"     386BSD man pages
27 .\"
28 .\" Modified 1993-03-29, David Metcalfe
29 .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
30 .\" 2006-01-15, mtk, Added example program.
31 .\"
32 .\" FIXME glibc 2.8 added qsort_r(), which needs to be documented.
33 .\"
34 .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi
35 .\"       all rights reserved.
36 .\" Translated 1997-01-21, YOSHINO Takashi <yoshino@civil.jcn.nihon-u.ac.jp>
37 .\" Updated & Modified 2004-06-06, Yuichi SATO <ysato444@yahoo.co.jp>
38 .\" Updated 2006-01-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
39 .\"
40 .TH QSORT 3 2009-09-15 "" "Linux Programmer's Manual"
41 .SH Ì¾Á°
42 qsort \- ÇÛÎó¤òʤÙÊѤ¨¤ë
43 .SH ½ñ¼°
44 .nf
45 .B #include <stdlib.h>
46 .sp
47 .BI "void qsort(void *" base ", size_t " nmemb ", size_t " size ,
48 .BI "           int(*" compar ")(const void *, const void *));"
49 .fi
50 .SH ÀâÌÀ
51 .BR qsort ()
52 ´Ø¿ô¤Ï¡¢
53 \fInmemb\fP ¸Ä¤ÎÂ礭¤µ \fIsize\fP ¤ÎÍ×ÁǤò¤â¤ÄÇÛÎó¤òʤÙÊѤ¨¤ë¡£
54 \fIbase\fP °ú¤­¿ô¤ÏÇÛÎó¤ÎÀèƬ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
55 .PP
56 \fIcompar\fP ¤ò¥Ý¥¤¥ó¥¿¤È¤¹¤ëÈæ³Ó´Ø¿ô¤Ë¤è¤Ã¤Æ¡¢
57 ÇÛÎó¤ÎÃæ¿È¤Ï¾º½ç (ÃͤÎÂ礭¤¤¤â¤Î¤Û¤É¸å¤ËʤֽçÈÖ) ¤Ëʤ٤é¤ì¤ë¡£
58 Èæ³Ó´Ø¿ô¤Î°ú¤­¿ô¤ÏÈæ³Ó¤µ¤ì¤ë¤Õ¤¿¤Ä¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£
59 .PP
60 Èæ³Ó´Ø¿ô¤Ï¡¢Âè°ì°ú¤­¿ô¤¬ÂèÆó°ú¤­¿ô¤ËÂФ·¤Æ¡¢
61 1) ¾®¤µ¤¤¡¢2) Åù¤·¤¤¡¢3) Â礭¤¤¤Î¤½¤ì¤¾¤ì¤Ë±þ¤¸¤Æ¡¢
62 1) ¥¼¥í¤è¤ê¾®¤µ¤¤À°¿ô¡¢2) ¥¼¥í¡¢3) ¥¼¥í¤è¤êÂ礭¤¤À°¿ô¤Î
63 ¤¤¤º¤ì¤«¤òÊÖ¤µ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
64 Æó¤Ä¤ÎÍ×ÁǤÎÈæ³Ó·ë²Ì¤¬Åù¤·¤¤¤È¤­¡¢
65 ʤÙÊѤ¨¤¿¸å¤ÎÇÛÎó¤Ç¤Ï¡¢¤³¤ì¤éÆó¤Ä¤Î½ç½ø¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
66 .SH ÊÖ¤êÃÍ
67 .BR qsort ()
68 ¤ÏÃͤòÊÖ¤µ¤Ê¤¤¡£
69 .SH ½àµò
70 SVr4, 4.3BSD, C89, C99.
71 .SH Ãí°Õ
72 .I compar
73 °ú¤­¿ô¤Ë»ÈÍѤ¹¤ë¤Î¤ËŬ¤·¤Æ¤¤¤ë¥é¥¤¥Ö¥é¥ê¥ë¡¼¥Á¥ó¤È¤·¤Æ¤Ï
74 .BR alphasort (3),
75 .BR versionsort (3)
76 ¤¬¤¢¤ë¡£
77 C ¤Îʸ»úÎó¤òÈæ³Ó¤¹¤ë¾ì¹ç¡¢°Ê²¼¤ÎÎã¤Ë¤¢¤ë¤è¤¦¤ËÈæ³Ó´Ø¿ô¤Ç
78 .BR strcmp (3)
79 ¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤â¤Ç¤­¤ë¡£
80 .SH Îã
81 »ÈÍÑÎã¤Ë¤Ä¤¤¤Æ¤Ï¡¢
82 .BR bsearch (3)
83 ¤Ë¤¢¤ëÎã¤ò»²¾È¤¹¤ë¤³¤È¡£
84
85 °Ê²¼¤Î¥×¥í¥°¥é¥à¤ËÊ̤λÈÍÑÎã¤ò¼¨¤¹¡£¤³¤Î¥×¥í¥°¥é¥à¤Ï¡¢
86 ¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ç»ØÄꤵ¤ì¤¿Ê¸»úÎó¤ÎʤӴ¹¤¨¤ò¹Ô¤¦¡£
87 .sp
88 .nf
89 #include <stdio.h>
90 #include <stdlib.h>
91 #include <string.h>
92
93 static int
94 cmpstringp(const void *p1, const void *p2)
95 {
96     /* ¤³¤Î´Ø¿ô¤Î¼ÂºÝ¤Î°ú¤­¿ô¤Ï "char ·¿¤Ø¤Î¥Ý¥¤¥ó¥¿¤Î¥Ý¥¤¥ó¥¿" ¤À¤¬¡¢
97        strcmp(3) ¤Î°ú¤­¿ô¤Ï "char ·¿¤Ø¤Î¥Ý¥¤¥ó¥¿" ¤Ç¤¢¤ë¡£
98        ¤½¤³¤Ç¡¢°Ê²¼¤Î¤è¤¦¤Ë¥­¥ã¥¹¥È¤ò¤·¤Æ¤«¤é¥Ý¥¤¥ó¥¿¤ÎµÕ»²¾È¤ò¹Ô¤¦¡£*/
99
100     return strcmp(* (char * const *) p1, * (char * const *) p2);
101 }
102
103 int
104 main(int argc, char *argv[])
105 {
106     int j;
107
108     if (argc < 2) {
109         fprintf(stderr, "Usage: %s <string>...\\n", argv[0]);
110         exit(EXIT_FAILURE);
111     }
112
113     qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);
114
115     for (j = 1; j < argc; j++)
116         puts(argv[j]);
117     exit(EXIT_SUCCESS);
118 }
119 .fi
120 .SH ´ØÏ¢¹àÌÜ
121 .BR sort (1),
122 .BR alphasort (3),
123 .BR strcmp (3),
124 .BR versionsort (3)