亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
国产精品国产三级国产a | 日韩一区二区不卡| 2014亚洲片线观看视频免费| 一区二区三区四区不卡在线 | 亚洲免费在线播放| 久久国产精品露脸对白| 91视频91自| 国产精品视频观看| 狠狠色丁香婷婷综合| 精品污污网站免费看| 国产精品久99| 国产乱码精品一品二品| 日韩美一区二区三区| 亚洲成人黄色影院| 色一区在线观看| 亚洲少妇中出一区| 丁香亚洲综合激情啪啪综合| 日韩精品中文字幕在线不卡尤物| 一区二区三区成人在线视频| 91女神在线视频| 国产精品欧美一区喷水| 高清不卡在线观看| 久久夜色精品国产欧美乱极品| 日欧美一区二区| 欧美日韩和欧美的一区二区| 亚洲一区二区影院| 欧美亚洲国产一区在线观看网站| 亚洲精品五月天| 色综合一个色综合| 一区二区三区在线影院| 91在线国产观看| 亚洲免费在线播放| 欧美亚洲国产一卡| 五月婷婷激情综合| 欧美一区二区在线观看| 美女视频网站久久| 337p粉嫩大胆噜噜噜噜噜91av | 一区二区三区欧美日韩| 色女孩综合影院| 一区二区三国产精华液| 欧美日韩一区在线观看| 午夜欧美在线一二页| 91麻豆精品国产91久久久久久 | 亚洲色图一区二区| 色狠狠色噜噜噜综合网| 亚洲成av人**亚洲成av**| 欧美日韩夫妻久久| 美女看a上一区| 欧美激情在线看| 91首页免费视频| 亚洲成va人在线观看| 欧美电影一区二区| 国产一区二区三区四| 国产精品乱人伦一区二区| 欧美在线一二三四区| 日韩电影在线看| 欧美激情艳妇裸体舞| 色综合色狠狠天天综合色| 亚洲国产毛片aaaaa无费看 | 制服丝袜中文字幕一区| 韩国在线一区二区| 亚洲日本va午夜在线电影| 欧美日韩国产乱码电影| 国产乱人伦偷精品视频免下载| 国产精品久久久久久久午夜片| 91丨porny丨最新| 日av在线不卡| 国产精品不卡一区| 欧美一区二区福利在线| 成人性视频免费网站| 日欧美一区二区| 国产精品理伦片| 日韩欧美高清在线| 色天天综合色天天久久| 狠狠色丁香九九婷婷综合五月| 亚洲同性同志一二三专区| 日韩欧美一级在线播放| 色综合久久久久综合体桃花网| 免费观看一级特黄欧美大片| 亚洲色图制服诱惑| 久久久久久久久久久久电影| 欧美三级午夜理伦三级中视频| 国产伦精品一区二区三区视频青涩 | 精品视频色一区| 国产成人免费在线观看不卡| 亚洲3atv精品一区二区三区| 国产精品天干天干在线综合| 欧美丰满嫩嫩电影| 91蜜桃网址入口| 国产乱码精品1区2区3区| 日韩国产欧美在线视频| 亚洲欧美二区三区| 国产精品全国免费观看高清| 日韩三区在线观看| 欧美日韩国产首页| 在线观看亚洲a| 成人黄色网址在线观看| 狠狠色丁香久久婷婷综合_中| 水蜜桃久久夜色精品一区的特点| 亚洲精品日韩综合观看成人91| 国产偷v国产偷v亚洲高清| 日韩一区二区精品葵司在线| 欧美人与z0zoxxxx视频| 日本韩国精品一区二区在线观看| 北岛玲一区二区三区四区| 国产精品影视网| 国产一区福利在线| 久久疯狂做爰流白浆xx| 免费一区二区视频| 日本中文字幕一区| 日本不卡一区二区三区高清视频| 亚洲午夜一区二区三区| 亚洲最大成人综合| 一区二区三区在线观看动漫 | 日本不卡视频一二三区| 亚洲成人1区2区| 午夜欧美2019年伦理| 日韩电影免费在线观看网站| 性做久久久久久久免费看| 午夜精品久久久久久不卡8050| 亚洲一区二区在线免费观看视频| 亚洲一区二区av电影| 五月天久久比比资源色| 午夜精品一区二区三区电影天堂| 亚洲成av人影院在线观看网| 日精品一区二区三区| 久久精品国产网站| 国产精品一区二区三区四区| 丁香婷婷深情五月亚洲| 99riav久久精品riav| 91美女在线观看| 精品视频999| 日韩欧美激情四射| 国产亚洲一二三区| 亚洲欧美国产77777| 五月天激情综合网| 国产精品影音先锋| 色婷婷亚洲一区二区三区| 欧美人牲a欧美精品| 欧美成人一区二区三区在线观看 | 亚洲制服丝袜在线| 麻豆国产一区二区| 成人中文字幕合集| 日本高清不卡视频| 日韩视频一区二区| 国产精品九色蝌蚪自拍| 亚洲超丰满肉感bbw| 国产揄拍国内精品对白| 99在线精品视频| 欧美精品aⅴ在线视频| 久久亚区不卡日本| 一区二区三区欧美日韩| 久久精品久久综合| 97久久人人超碰| 日韩欧美一区二区久久婷婷| 国产欧美一区二区三区沐欲| 亚洲一级片在线观看| 国产一区视频导航| 日本高清无吗v一区| 国产午夜精品理论片a级大结局| 亚洲四区在线观看| 国内精品久久久久影院一蜜桃| 93久久精品日日躁夜夜躁欧美| 欧美日本一道本| 国产精品久久久久久久久果冻传媒| 五月综合激情网| 成人av影院在线| 日韩限制级电影在线观看| 亚洲色图清纯唯美| 韩国v欧美v日本v亚洲v| 欧洲av在线精品| 国产欧美精品一区二区色综合朱莉| 性欧美大战久久久久久久久| eeuss鲁片一区二区三区在线观看| 日韩欧美激情在线| 五月婷婷久久丁香| 91丨porny丨中文| 国产精品免费人成网站| 日本不卡免费在线视频| 欧美日韩综合不卡| 亚洲精品国产一区二区三区四区在线| 国产乱码精品一区二区三区忘忧草 | 欧美一区二区三区在线视频| 亚洲视频每日更新| 国产成人无遮挡在线视频| 精品国产免费久久| 日韩国产精品久久| 欧美福利视频导航| 亚洲国产日韩精品| 欧美吻胸吃奶大尺度电影| 亚洲欧美日韩国产另类专区| 成人精品视频.| 中文字幕免费观看一区| 国产成人av电影在线| 久久久精品日韩欧美| 国产一区二区三区不卡在线观看 | 蜜桃视频一区二区| 日韩三级在线观看| 久久精品国产77777蜜臀| 日韩欧美国产wwwww|