亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? library_8.html

?? Glibc的中文手冊(cè)
?? HTML
字號(hào):
<!-- This HTML file has been created by texi2html 1.27
     from library.texinfo on 3 March 1994 -->

<TITLE>The GNU C Library - Searching and Sorting</TITLE>
<P>Go to the <A HREF="library_7.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_7.html">previous</A>, <A HREF="library_9.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_9.html">next</A> section.<P>
<H1><A NAME="SEC86" HREF="library_toc.html#SEC86" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC86">Searching and Sorting</A></H1>
<P>
This chapter describes functions for searching and sorting arrays of
arbitrary objects.  You pass the appropriate comparison function to be
applied as an argument, along with the size of the objects in the array
and the total number of elements.
<P>
<A NAME="IDX380"></A>
<H2><A NAME="SEC87" HREF="library_toc.html#SEC87" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC87">Defining the Comparison Function</A></H2>
<P>
In order to use the sorted array library functions, you have to describe
how to compare the elements of the array.
<P>
To do this, you supply a comparison function to compare two elements of
the array.  The library will call this function, passing as arguments
pointers to two array elements to be compared.  Your comparison function
should return a value the way <CODE>strcmp</CODE> (see section <A HREF="library_5.html#SEC62" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_5.html#SEC62">String/Array Comparison</A>) does: negative if the first argument is "less" than the
second, zero if they are "equal", and positive if the first argument
is "greater".
<P>
Here is an example of a comparison function which works with an array of
numbers of type <CODE>double</CODE>:
<P>
<PRE>
int
compare_doubles (const double *a, const double *b)
{
  double temp = *a - *b;
  if (temp &#62; 0)
    return 1;
  else if (temp &#60; 0)
    return -1;
  else
    return 0;
}
</PRE>
<P>
The header file <TT>`stdlib.h'</TT> defines a name for the data type of
comparison functions.  This is a GNU extension and thus defined only if
you request the GNU extensions.
<A NAME="IDX381"></A>
<P>
<PRE>
int comparison_fn_t (const void *, const void *);
</PRE>
<P>
<A NAME="IDX382"></A>
<A NAME="IDX383"></A>
<A NAME="IDX384"></A>
<H2><A NAME="SEC88" HREF="library_toc.html#SEC88" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC88">Array Search Function</A></H2>
<P>
To search a sorted array for an element matching the key, use the
<CODE>bsearch</CODE> function.  The prototype for this function is in
the header file <TT>`stdlib.h'</TT>.
<A NAME="IDX385"></A>
<P>
<A NAME="IDX386"></A>
<U>Function:</U> void * <B>bsearch</B> <I>(const void *<VAR>key</VAR>, const void *<VAR>array</VAR>, size_t <VAR>count</VAR>, size_t <VAR>size</VAR>, comparison_fn_t <VAR>compare</VAR>)</I><P>
The <CODE>bsearch</CODE> function searches the sorted array <VAR>array</VAR> for an object
that is equivalent to <VAR>key</VAR>.  The array contains <VAR>count</VAR> elements,
each of which is of size <VAR>size</VAR>.
<P>
The <VAR>compare</VAR> function is used to perform the comparison.  This
function is called with two pointer arguments and should return an
integer less than, equal to, or greater than zero corresponding to
whether its first argument is considered less than, equal to, or greater
than its second argument.  The elements of the <VAR>array</VAR> must already
be sorted in ascending order according to this comparison function.
<P>
The return value is a pointer to the matching array element, or a null
pointer if no match is found.  If the array contains more than one element
that matches, the one that is returned is unspecified.
<P>
This function derives its name from the fact that it is implemented
using the binary search.
<P>
<A NAME="IDX387"></A>
<A NAME="IDX388"></A>
<A NAME="IDX389"></A>
<H2><A NAME="SEC89" HREF="library_toc.html#SEC89" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC89">Array Sort Function</A></H2>
<P>
To sort an array using an arbitrary comparison function, use the
<CODE>qsort</CODE> function.  The prototype for this function is in
<TT>`stdlib.h'</TT>.
<A NAME="IDX390"></A>
<P>
<A NAME="IDX391"></A>
<U>Function:</U> void <B>qsort</B> <I>(void *<VAR>array</VAR>, size_t <VAR>count</VAR>, size_t <VAR>size</VAR>, comparison_fn_t <VAR>compare</VAR>)</I><P>
The <VAR>qsort</VAR> function sorts the array <VAR>array</VAR>.  The array contains
<VAR>count</VAR> elements, each of which is of size <VAR>size</VAR>.
<P>
The <VAR>compare</VAR> function is used to perform the comparison on the
array elements.  This function is called with two pointer arguments and
should return an integer less than, equal to, or greater than zero
corresponding to whether its first argument is considered less than,
equal to, or greater than its second argument.
<A NAME="IDX392"></A>
<P>
<STRONG>Warning:</STRONG> If two objects compare as equal, their order after
sorting is unpredictable.  That is to say, the sorting is not stable.
This can make a difference when the comparison considers only part of
the elements.  Two elements with the same sort key may differ in other
respects.
<P>
If you want the effect of a stable sort, you can get this result by
writing the comparison function so that, lacking other reason
distinguish between two elements, it compares them by their addresses.
<P>
Here is a simple example of sorting an array of doubles in numerical
order, using the comparison function defined above (see section <A HREF="library_8.html#SEC87" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_8.html#SEC87">Defining the Comparison Function</A>):
<P>
<PRE>
{
  double *array;
  int size;
  ...
  qsort (array, size, sizeof (double), compare_doubles);
}
</PRE>
<P>
The <CODE>qsort</CODE> function derives its name from the fact that it was
originally implemented using the algorithm "quick sort".
<P>
<H2><A NAME="SEC90" HREF="library_toc.html#SEC90" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC90">Searching and Sorting Example</A></H2>
<P>
Here is an example showing the use of <CODE>qsort</CODE> and <CODE>bsearch</CODE>
with an array of structures.  The objects in the array are sorted
by comparing their <CODE>name</CODE> fields with the <CODE>strcmp</CODE> function.
Then, we can look up individual objects based on their names.
<P>
<PRE>
#include &#60;stdlib.h&#62;
#include &#60;stdio.h&#62;
#include &#60;string.h&#62;

/* Define an array of critters to sort.  */

struct critter
{
  char *name;
  char *species;
};

struct critter muppets[]=
{
  {"Kermit", "frog"},
  {"Piggy", "pig"},
  {"Gonzo", "whatever"},
  {"Fozzie", "bear"},
  {"Sam", "eagle"},
  {"Robin", "frog"},
  {"Animal", "animal"},
  {"Camilla", "chicken"},
  {"Sweetums", "monster"},
  {"Dr. Strangepork", "pig"},
  {"Link Hogthrob", "pig"},
  {"Zoot", "human"},
  {"Dr. Bunsen Honeydew", "human"},
  {"Beaker", "human"},
  {"Swedish Chef", "human"}};

int count = sizeof (muppets) / sizeof (struct critter);



/* This is the comparison function used for sorting and searching.  */

int 
critter_cmp (const struct critter *c1, const struct critter *c2)
{
  return strcmp (c1-&#62;name, c2-&#62;name);
}


/* Print information about a critter.  */

void 
print_critter (const struct critter *c)
{
  printf ("%s, the %s\n", c-&#62;name, c-&#62;species);
}


/* Do the lookup into the sorted array.  */

void 
find_critter (char *name)
{
  struct critter target, *result;
  target.name = name;
  result = bsearch (&#38;target, muppets, count, sizeof (struct critter),
		    critter_cmp);
  if (result)
    print_critter (result);
  else
    printf ("Couldn't find %s.\n", name);
}

/* Main program.  */

int
main (void)
{
  int i;

  for (i = 0; i &#60; count; i++)
    print_critter (&#38;muppets[i]);
  printf ("\n");

  qsort (muppets, count, sizeof (struct critter), critter_cmp);

  for (i = 0; i &#60; count; i++)
    print_critter (&#38;muppets[i]);
  printf ("\n");

  find_critter ("Kermit");
  find_critter ("Gonzo");
  find_critter ("Janice");

  return 0;
}
</PRE>
<A NAME="IDX393"></A>
<P>
The output from this program looks like:
<P>
<PRE>
Animal, the animal
Beaker, the human
Camilla, the chicken
Dr. Bunsen Honeydew, the human
Dr. Strangepork, the pig
Fozzie, the bear
Gonzo, the whatever
Kermit, the frog
Link Hogthrob, the pig
Piggy, the pig
Robin, the frog
Sam, the eagle
Swedish Chef, the human
Sweetums, the monster
Zoot, the human


Kermit, the frog
Gonzo, the whatever
Couldn't find Janice.
</PRE>
<P>
<P>Go to the <A HREF="library_7.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_7.html">previous</A>, <A HREF="library_9.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_9.html">next</A> section.<P>

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜av一区二区| 一本大道久久a久久综合| 九色综合狠狠综合久久| 老司机精品视频导航| 蜜桃一区二区三区四区| 美女视频网站黄色亚洲| 国产一区日韩二区欧美三区| 国产精品一级在线| 成人免费毛片片v| 91亚洲精华国产精华精华液| 色综合激情五月| 精品视频免费看| 欧美一级高清片在线观看| 日韩一级欧美一级| 久久久青草青青国产亚洲免观| 国产日韩av一区二区| 中文字幕精品在线不卡| 亚洲三级电影网站| 亚洲成av人片一区二区| 美女在线视频一区| 国产精一品亚洲二区在线视频| 国产精品 日产精品 欧美精品| 99视频在线精品| 欧美日韩一区二区三区高清| 日韩视频免费观看高清完整版 | 精品成人私密视频| 国产欧美日韩久久| 一区二区三区在线高清| 日韩国产精品大片| 国产99久久久国产精品潘金网站| 99视频精品免费视频| 欧美视频自拍偷拍| www国产精品av| 亚洲人吸女人奶水| 日本欧美一区二区在线观看| 国产suv精品一区二区6| 欧洲色大大久久| 精品国产一区二区国模嫣然| 成人欧美一区二区三区白人 | 一区二区日韩av| 美日韩一区二区三区| 成人高清视频在线观看| 欧美高清hd18日本| 久久精品欧美日韩精品| 亚洲香肠在线观看| 国产福利精品导航| 欧美日韩国产精品成人| 国产欧美一区二区在线观看| 亚洲v中文字幕| 成人做爰69片免费看网站| 欧美日本一道本在线视频| 久久精品亚洲国产奇米99| 亚洲永久精品国产| 国产91对白在线观看九色| 欧美影院精品一区| 国产目拍亚洲精品99久久精品| 亚洲va欧美va人人爽| 懂色中文一区二区在线播放| 91精品久久久久久久99蜜桃| 中文字幕在线不卡一区二区三区 | 91精品在线麻豆| 国产精品国产三级国产普通话99 | 久草这里只有精品视频| 91猫先生在线| 国产日韩欧美不卡| 美女视频黄久久| 欧美系列一区二区| 亚洲欧洲成人精品av97| 久久av老司机精品网站导航| 欧美丝袜丝nylons| 亚洲欧洲美洲综合色网| 国产一区二区精品久久| 91精品国产91久久综合桃花 | 国产精品18久久久久久久网站| 欧美亚洲综合色| 国产精品久久三区| 国产激情视频一区二区在线观看| 欧美一区二区三区在线看| 亚洲精品自拍动漫在线| 国产综合成人久久大片91| 91麻豆精品国产综合久久久久久| 一区二区视频在线看| 99久精品国产| 久久免费电影网| 麻豆传媒一区二区三区| 欧美日韩国产精选| 亚洲韩国精品一区| 在线观看亚洲a| 一区二区三区美女视频| 99re热这里只有精品免费视频| 国产蜜臀97一区二区三区| 国产一区视频导航| 26uuu久久综合| 激情成人综合网| 久久综合九色综合欧美98 | av不卡在线播放| 国产肉丝袜一区二区| 国产精品一二三区| 国产拍欧美日韩视频二区| 国产jizzjizz一区二区| 国产视频视频一区| 粉嫩嫩av羞羞动漫久久久| 亚洲国产精品二十页| 成人app在线观看| 中文字幕欧美一| 99re热这里只有精品免费视频| 亚洲欧美综合网| 色综合色综合色综合| 亚洲女同一区二区| 色美美综合视频| 亚洲综合色视频| 欧美日韩在线精品一区二区三区激情 | 久久久久久久久久电影| 国产高清不卡一区| 亚洲欧洲日韩综合一区二区| 91福利小视频| 亚洲高清中文字幕| 欧美一区二区视频在线观看| 久久99精品久久久| 欧美国产日韩一二三区| 972aa.com艺术欧美| 亚洲一区二区视频在线观看| 欧美老年两性高潮| 精品一区二区免费看| 欧美国产日韩精品免费观看| 91丨porny丨国产入口| 亚洲国产精品一区二区久久| 日韩一区二区在线观看视频| 国产精品一区二区你懂的| 亚洲天堂精品视频| 欧美综合一区二区| 久久99精品网久久| 中文字幕成人在线观看| 在线观看日产精品| 蜜桃精品视频在线| 国产精品灌醉下药二区| 欧美日韩免费观看一区三区| 久久国产剧场电影| 亚洲日本电影在线| 日韩欧美资源站| 成人高清视频在线| 日韩av不卡一区二区| 日本一区二区成人| 欧美高清一级片在线| 粉嫩av一区二区三区在线播放 | 色诱亚洲精品久久久久久| 视频一区二区三区在线| 国产亚洲一区二区三区在线观看 | 欧美一区二区三区免费视频 | 在线一区二区三区| 国产一区视频网站| 亚洲综合清纯丝袜自拍| 日韩精品自拍偷拍| 在线精品观看国产| 国产伦理精品不卡| 亚洲国产一区二区a毛片| 久久先锋资源网| 欧美日韩一二三| 不卡一二三区首页| 久久精品99国产精品日本| 亚洲欧美国产77777| 久久伊99综合婷婷久久伊| 欧美无人高清视频在线观看| 福利电影一区二区三区| 视频在线观看91| 中文字幕综合网| 久久人人超碰精品| 91精品国产综合久久精品| 99久久777色| 国产成人免费在线观看不卡| jlzzjlzz国产精品久久| 日韩精品国产精品| 亚洲欧洲综合另类| 欧美国产精品久久| 欧美mv日韩mv亚洲| 欧美日韩国产片| 色诱视频网站一区| 成人免费视频一区二区| 国模无码大尺度一区二区三区| 日韩av一区二区三区四区| 亚洲制服欧美中文字幕中文字幕| 国产视频视频一区| 久久综合一区二区| 欧美电影免费提供在线观看| 欧美老肥妇做.爰bbww视频| 色综合久久中文字幕综合网| 成人午夜视频网站| 国产成人自拍网| 国产精品正在播放| 久草在线在线精品观看| 日韩精品视频网站| 亚洲国产va精品久久久不卡综合| 亚洲欧洲综合另类| 亚洲欧美日韩精品久久久久| 中文字幕中文字幕一区二区| 国产亚洲欧洲997久久综合 | 久久青草欧美一区二区三区| 日韩一级完整毛片| 日韩视频在线一区二区| 日韩一区二区三区视频在线|