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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? qsort.c

?? 遺傳算法工具
?? C
字號:
/*-
 * Copyright (c) 1980, 1983, 1990 The Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)qsort.c	5.9 (Berkeley) 2/23/91";
#endif /* LIBC_SCCS and not lint */

#include <sys/types.h>
#include <stdlib.h>

#if __STDC__ || defined(__cplusplus)
#define __P(s) s
#else
#define __P(s) ()
#endif

/*
 * MTHRESH is the smallest partition for which we compare for a median
 * value instead of using the middle value.
 */
#define	MTHRESH	6

/*
 * THRESH is the minimum number of entries in a partition for continued
 * partitioning.
 */
#define	THRESH	4

void
bsd_qsort(bot, nmemb, size, compar)
	void *bot;
	size_t nmemb, size;
	int (*compar) __P((const void *, const void *));
{
	static void insertion_sort(), quick_sort();

	if (nmemb <= 1)
		return;

	if (nmemb >= THRESH)
		quick_sort(bot, nmemb, size, compar);
	else
		insertion_sort(bot, nmemb, size, compar);
}

/*
 * Swap two areas of size number of bytes.  Although qsort(3) permits random
 * blocks of memory to be sorted, sorting pointers is almost certainly the
 * common case (and, were it not, could easily be made so).  Regardless, it
 * isn't worth optimizing; the SWAP's get sped up by the cache, and pointer
 * arithmetic gets lost in the time required for comparison function calls.
 */
#define	SWAP(a, b) { \
	cnt = size; \
	do { \
		ch = *a; \
		*a++ = *b; \
		*b++ = ch; \
	} while (--cnt); \
}

/*
 * Knuth, Vol. 3, page 116, Algorithm Q, step b, argues that a single pass
 * of straight insertion sort after partitioning is complete is better than
 * sorting each small partition as it is created.  This isn't correct in this
 * implementation because comparisons require at least one (and often two)
 * function calls and are likely to be the dominating expense of the sort.
 * Doing a final insertion sort does more comparisons than are necessary
 * because it compares the "edges" and medians of the partitions which are
 * known to be already sorted.
 *
 * This is also the reasoning behind selecting a small THRESH value (see
 * Knuth, page 122, equation 26), since the quicksort algorithm does less
 * comparisons than the insertion sort.
 */
#define	SORT(bot, n) { \
	if (n > 1) \
		if (n == 2) { \
			t1 = bot + size; \
			if (compar(t1, bot) < 0) \
				SWAP(t1, bot); \
		} else \
			insertion_sort(bot, n, size, compar); \
}

static void
quick_sort(bot, nmemb, size, compar)
	register char *bot;
	register int size;
	int nmemb, (*compar)();
{
	register int cnt;
	register u_char ch;
	register char *top, *mid, *t1, *t2;
	register int n1, n2;
	char *bsv;
	static void insertion_sort();

	/* bot and nmemb must already be set. */
partition:

	/* find mid and top elements */
	mid = bot + size * (nmemb >> 1);
	top = bot + (nmemb - 1) * size;

	/*
	 * Find the median of the first, last and middle element (see Knuth,
	 * Vol. 3, page 123, Eq. 28).  This test order gets the equalities
	 * right.
	 */
	if (nmemb >= MTHRESH) {
		n1 = compar(bot, mid);
		n2 = compar(mid, top);
		if (n1 < 0 && n2 > 0)
			t1 = compar(bot, top) < 0 ? top : bot;
		else if (n1 > 0 && n2 < 0)
			t1 = compar(bot, top) > 0 ? top : bot;
		else
			t1 = mid;

		/* if mid element not selected, swap selection there */
		if (t1 != mid) {
			SWAP(t1, mid);
			mid -= size;
		}
	}

	/* Standard quicksort, Knuth, Vol. 3, page 116, Algorithm Q. */
#define	didswap	n1
#define	newbot	t1
#define	replace	t2
	didswap = 0;
	for (bsv = bot;;) {
		for (; bot < mid && compar(bot, mid) <= 0; bot += size);
		while (top > mid) {
			if (compar(mid, top) <= 0) {
				top -= size;
				continue;
			}
			newbot = bot + size;	/* value of bot after swap */
			if (bot == mid)		/* top <-> mid, mid == top */
				replace = mid = top;
			else {			/* bot <-> top */
				replace = top;
				top -= size;
			}
			goto swap;
		}
		if (bot == mid)
			break;

		/* bot <-> mid, mid == bot */
		replace = mid;
		newbot = mid = bot;		/* value of bot after swap */
		top -= size;

swap:		SWAP(bot, replace);
		bot = newbot;
		didswap = 1;
	}

	/*
	 * Quicksort behaves badly in the presence of data which is already
	 * sorted (see Knuth, Vol. 3, page 119) going from O N lg N to O N^2.
	 * To avoid this worst case behavior, if a re-partitioning occurs
	 * without swapping any elements, it is not further partitioned and
	 * is insert sorted.  This wins big with almost sorted data sets and
	 * only loses if the data set is very strangely partitioned.  A fix
	 * for those data sets would be to return prematurely if the insertion
	 * sort routine is forced to make an excessive number of swaps, and
	 * continue the partitioning.
	 */
	if (!didswap) {
		insertion_sort(bsv, nmemb, size, compar);
		return;
	}

	/*
	 * Re-partition or sort as necessary.  Note that the mid element
	 * itself is correctly positioned and can be ignored.
	 */
#define	nlower	n1
#define	nupper	n2
	bot = bsv;
	nlower = (mid - bot) / size;	/* size of lower partition */
	mid += size;
	nupper = nmemb - nlower - 1;	/* size of upper partition */

	/*
	 * If must call recursively, do it on the smaller partition; this
	 * bounds the stack to lg N entries.
	 */
	if (nlower > nupper) {
		if (nupper >= THRESH)
			quick_sort(mid, nupper, size, compar);
		else {
			SORT(mid, nupper);
			if (nlower < THRESH) {
				SORT(bot, nlower);
				return;
			}
		}
		nmemb = nlower;
	} else {
		if (nlower >= THRESH)
			quick_sort(bot, nlower, size, compar);
		else {
			SORT(bot, nlower);
			if (nupper < THRESH) {
				SORT(mid, nupper);
				return;
			}
		}
		bot = mid;
		nmemb = nupper;
	}
	goto partition;
	/* NOTREACHED */
}

static void
insertion_sort(bot, nmemb, size, compar)
	char *bot;
	register int size;
	int nmemb, (*compar)();
{
	register int cnt;
	register u_char ch;
	register char *s1, *s2, *t1, *t2, *top;

	/*
	 * A simple insertion sort (see Knuth, Vol. 3, page 81, Algorithm
	 * S).  Insertion sort has the same worst case as most simple sorts
	 * (O N^2).  It gets used here because it is (O N) in the case of
	 * sorted data.
	 */
	top = bot + nmemb * size;
	for (t1 = bot + size; t1 < top;) {
		for (t2 = t1; (t2 -= size) >= bot && compar(t1, t2) < 0;);
		if (t1 != (t2 += size)) {
			/* Bubble bytes up through each element. */
			for (cnt = size; cnt--; ++t1) {
				ch = *t1;
				for (s1 = s2 = t1; (s2 -= size) >= t2; s1 = s2)
					*s1 = *s2;
				*s1 = ch;
			}
		} else
			t1 += size;
	}
}
ot && compar(t1, t2) < 0;);
		if (t1 != (t2 += size)) {
			/* Bubble bytes up through each element. */
			for (cnt = size; cnt--; ++t1) {
				ch = *t1;
				for (s1 = s2 = t1; (s2 -= size) >= t2; s1 = s2)
					*s1 = *s2;
				*s1 = ch;
			}
		} else
			t1 += size;
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品无码三级在线观看视频| 国模一区二区三区白浆| 免费精品视频最新在线| 免费看日韩精品| 国产成人午夜高潮毛片| 色婷婷综合久久| 91精品婷婷国产综合久久竹菊| 久久综合九色综合欧美亚洲| 一区在线观看视频| 日韩**一区毛片| 成人午夜电影久久影院| 欧美日韩一卡二卡| 久久久精品2019中文字幕之3| 一区二区三区国产精品| 国产在线一区观看| 欧美三区在线视频| 国产精品女同一区二区三区| 亚洲成年人网站在线观看| 国产成人aaa| 精品视频123区在线观看| 国产欧美一区二区精品性色| 亚洲国产精品一区二区尤物区| 激情图区综合网| 欧美日韩在线播放三区四区| 欧美激情综合五月色丁香小说| 亚洲国产成人porn| 久久在线观看免费| 欧洲一区二区av| 日韩欧美黄色影院| 自拍偷拍亚洲欧美日韩| 亚洲aaa精品| 麻豆精品视频在线观看免费 | 欧美国产视频在线| 一区二区三区免费看视频| 久久69国产一区二区蜜臀| 一本久道久久综合中文字幕| 欧美精品一区视频| 性欧美疯狂xxxxbbbb| 成人激情动漫在线观看| 精品久久久久久久久久久久久久久久久| 亚洲精品视频自拍| 国产69精品久久久久777| 欧美一区二区三区爱爱| 亚洲在线观看免费| 色综合久久久久| 国产拍揄自揄精品视频麻豆| 免费在线观看视频一区| 欧美日韩一区二区在线观看视频| 国产精品女同互慰在线看 | 久久国产精品99久久久久久老狼| av午夜一区麻豆| 久久午夜羞羞影院免费观看| 天堂一区二区在线| 91国产丝袜在线播放| 国产精品家庭影院| 国产一二精品视频| 精品国产污污免费网站入口| 日韩国产成人精品| 欧美日韩国产系列| 亚洲伊人伊色伊影伊综合网| 色婷婷久久久久swag精品| 亚洲少妇中出一区| av电影在线观看一区| 亚洲国产高清不卡| 大陆成人av片| 国产精品美女视频| www.久久久久久久久| 国产精品无遮挡| 成人丝袜18视频在线观看| 欧美国产日产图区| 成人av影视在线观看| 国产精品成人在线观看| 不卡视频免费播放| 成人免费一区二区三区视频| 91在线国内视频| 亚洲日本va午夜在线电影| 91无套直看片红桃| 91色porny蝌蚪| 欧美日韩不卡在线| 亚洲视频一区在线| 91在线观看美女| 亚洲黄色av一区| 欧美午夜精品一区| 香蕉成人啪国产精品视频综合网| 欧美日韩精品专区| 免费观看91视频大全| 欧美α欧美αv大片| 国产在线不卡一卡二卡三卡四卡| 久久色在线视频| 国产盗摄视频一区二区三区| 国产欧美综合色| 色综合久久六月婷婷中文字幕| 亚洲综合丝袜美腿| 51精品久久久久久久蜜臀| 蜜桃视频一区二区| 国产蜜臀av在线一区二区三区| 成人app网站| 亚洲国产精品人人做人人爽| 欧美一区二区观看视频| 欧美aa在线视频| 久久在线观看免费| 91免费观看国产| 亚洲国产视频一区二区| 制服丝袜日韩国产| 国产在线麻豆精品观看| 一区免费观看视频| 欧美日韩小视频| 国产一区二区三区观看| 亚洲男人天堂av| 日韩一区二区精品葵司在线| 国产成人亚洲综合a∨婷婷| 一区二区三区精品视频| 日韩三级中文字幕| 成人美女视频在线观看| 亚洲福利一二三区| 亚洲靠逼com| 欧美精品在线观看播放| 国产在线播放一区三区四| 亚洲免费av高清| 日韩欧美一级二级| 99久久久精品| 日日骚欧美日韩| 中文字幕精品—区二区四季| 欧美亚洲另类激情小说| 精品在线一区二区三区| 亚洲精品福利视频网站| 2017欧美狠狠色| 欧美天天综合网| 成人做爰69片免费看网站| 香蕉成人啪国产精品视频综合网| 欧美国产亚洲另类动漫| 欧美一区二区在线免费播放| 不卡视频免费播放| 久久精品国产秦先生| 亚洲综合av网| 国产欧美精品在线观看| 精品一区二区影视| 色呦呦网站一区| 免费日本视频一区| 亚洲人一二三区| 国产香蕉久久精品综合网| 欧美日本在线观看| 91蜜桃传媒精品久久久一区二区| 久久成人久久鬼色| 亚洲成人一区二区在线观看| 国产欧美日韩精品在线| 日韩欧美激情在线| 欧美美女喷水视频| 91亚洲永久精品| 大胆亚洲人体视频| 国产一区二区剧情av在线| 日韩中文字幕1| 一区二区在线观看视频| 国产精品色哟哟网站| 欧美成人激情免费网| 欧美乱妇15p| 91久久精品一区二区| 国产精品99久久久久久宅男| 免费av成人在线| 亚洲.国产.中文慕字在线| 亚洲黄色在线视频| 国产精品久久久久影视| 国产亚洲人成网站| 精品欧美久久久| 91精品国产色综合久久| 欧美三级日韩三级国产三级| 91美女片黄在线观看91美女| 成人免费av在线| 成人在线一区二区三区| 国产成人精品免费| 国产成人激情av| 国产99久久久国产精品潘金网站| 韩国毛片一区二区三区| 另类小说一区二区三区| 日韩国产欧美三级| 午夜一区二区三区视频| 亚洲一卡二卡三卡四卡无卡久久| 亚洲欧美成aⅴ人在线观看| 中文字幕制服丝袜一区二区三区 | 久久99久久精品欧美| 视频在线观看一区二区三区| 亚洲高清三级视频| 亚洲成人手机在线| 日日夜夜精品视频免费| 奇米影视一区二区三区小说| 日韩电影在线免费| 蜜芽一区二区三区| 老司机精品视频在线| 久久精品国产澳门| 韩国在线一区二区| 国产精品18久久久久久久久| 国产乱妇无码大片在线观看| 国产98色在线|日韩| www.亚洲色图| 色综合久久88色综合天天6| 欧美色男人天堂| 欧美高清视频www夜色资源网| 日韩欧美黄色影院| 国产午夜精品一区二区三区视频| 国产精品久久久久久久久免费樱桃|