<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ubuntu,debian,redhat -linuxany.com &#187; bsearch</title>
	<atom:link href="http://www.linuxany.com/archives/tag/bsearch/feed" rel="self" type="application/rss+xml" />
	<link>http://www.linuxany.com</link>
	<description>ubuntu,debian,redhat,fedora,centos</description>
	<lastBuildDate>Thu, 29 Jul 2010 13:01:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>排序与查找函数(qsort,bsearch,alphasort)</title>
		<link>http://www.linuxany.com/archives/918.html</link>
		<comments>http://www.linuxany.com/archives/918.html#comments</comments>
		<pubDate>Sun, 27 Dec 2009 06:07:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[alphasort]]></category>
		<category><![CDATA[bsearch]]></category>
		<category><![CDATA[qsort]]></category>

		<guid isPermaLink="false">http://www.linuxany.com/?p=918</guid>
		<description><![CDATA[qsort函数声明如下：
void qsort(void *base, size_t nmemb, size_t size,
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; int(*compar)(const&#160;void *, const void *));
参数说明如下：
base: 要排序的数组
nmemb: 数组中的元素数目 sizeof(array)/sizeof(array[0])
size: 每个数组元素占用内存空间，可使用sizeof(array[0])获得
compar: 比较两个数组元素的比较函数。本比较函数的第一个参数值小于、等于、大于第二参数值时，本比较函数的返回值应分别小于、等于、大于零。

bsearch函数声明如下：
void *bsearch(const void *key, const void *base, size_t *nelem,
size_t&#160;width, int(*fcmp)(const void *, const *));
参数的意思和qsort的差不多，区别在于：
1. qsort用来排序，bsearch用二分法来查找元素
2. bsearch中的base必须是升序排列的数组
3. 如果数组里有重复的答案，则bsearch会返回其中一个的地址 （具体返回哪一个不确定）
4. bsearch有五个自变量，第一个是要找的东西，剩下的跟qsort一模一样
5. bsearch如果没找到所求则回传NULL ，否则回传该元素被找到的地址(void *)
qsort()和bsearch()的用法
使用qsort()排序 并 用 bsearch（）搜索是一个比较常用的组合，使用方便快捷。
比如：对一个长为1000的数组进行排序时，int a[1000]; 那么base应为a，num应为 1000，width应为 sizeof(int)，comp函数随自己的命名。
qsort(a,1000,sizeof(int ),comp);
//其中comp函数应写为:
int&#160;comp(const void [...]]]></description>
		<wfw:commentRss>http://www.linuxany.com/archives/918.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
