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

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

?? qsort.c

?? 簡單遺傳算法經典例子!! SGPC: Simple Genetic Programming in C by Walter Alden Tackett and Aviram Carmi
?? 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一区二区三区免费野_久草精品视频
国产精品一二三四区| 日韩毛片视频在线看| 色老头久久综合| 成人高清在线视频| 国产精品18久久久久久vr| 韩国v欧美v日本v亚洲v| 国产一区二区剧情av在线| 久久99精品国产麻豆婷婷洗澡| 青娱乐精品视频在线| 蜜臀av一区二区在线观看| 七七婷婷婷婷精品国产| 老司机一区二区| 国产精品综合二区| 成人夜色视频网站在线观看| 91理论电影在线观看| 色综合久久久久久久久久久| 日本韩国一区二区| 欧美日韩国产系列| 欧美大白屁股肥臀xxxxxx| 久久婷婷国产综合精品青草| 久久久一区二区三区| 亚洲欧洲美洲综合色网| 亚洲色图.com| 日本系列欧美系列| 国产成人亚洲综合a∨婷婷| 丁香六月久久综合狠狠色| 91高清在线观看| 欧美一区二区三区色| 国产午夜精品美女毛片视频| 综合久久综合久久| 丝袜美腿亚洲一区二区图片| 国产一区三区三区| 色婷婷精品大在线视频| 欧美精品自拍偷拍动漫精品| www国产精品av| 一区二区三区鲁丝不卡| 日本成人超碰在线观看| 成人国产一区二区三区精品| 欧美日韩精品三区| 国产精品久久一级| 偷拍日韩校园综合在线| 成人黄色在线视频| 欧美精品xxxxbbbb| 国产精品久久久一本精品| 亚洲超碰精品一区二区| 国产成人免费视频网站高清观看视频| 在线精品国精品国产尤物884a| 精品久久久久久久人人人人传媒 | 欧美一区二区精美| 中文字幕一区在线| 另类综合日韩欧美亚洲| 一本久久a久久免费精品不卡| 欧美一区2区视频在线观看| 国产精品国模大尺度视频| 久久福利资源站| 欧美日韩国产综合一区二区三区 | 色94色欧美sute亚洲线路二 | 欧美国产在线观看| 日本免费新一区视频| 在线亚洲欧美专区二区| 国产拍揄自揄精品视频麻豆| 激情综合亚洲精品| 欧美精品精品一区| 亚洲高清免费观看高清完整版在线观看| 国产成人综合亚洲网站| 欧美r级电影在线观看| 日韩av二区在线播放| 欧美美女bb生活片| 亚洲成人动漫av| 欧美日韩视频第一区| 亚洲成人午夜影院| 欧美日韩综合在线免费观看| 一区二区三区四区五区视频在线观看| 国产不卡高清在线观看视频| 久久久久一区二区三区四区| 九九九精品视频| 欧美成人vps| 激情综合一区二区三区| 亚洲精品在线免费观看视频| 日本欧美一区二区| 精品免费日韩av| 国产在线精品一区二区| 久久久久久久久久久久电影| 国产成人免费网站| 国产精品丝袜久久久久久app| 国产在线不卡一卡二卡三卡四卡| 国产色一区二区| 丁香六月综合激情| 一区二区视频在线| 欧美日韩一级视频| 青青草国产精品97视觉盛宴 | 狠狠色综合播放一区二区| 精品播放一区二区| 国产成人精品亚洲777人妖| 中文字幕av资源一区| 色天天综合色天天久久| 日韩在线一区二区| 欧美精品一区二区三区很污很色的| 久久国产精品第一页| 久久人人爽爽爽人久久久| 成人app下载| 日韩国产一二三区| 欧美激情一区二区三区在线| 色欧美片视频在线观看| 午夜在线成人av| 久久无码av三级| 99久久精品国产一区| 亚洲成a人片在线观看中文| 日韩美女一区二区三区四区| 成人精品一区二区三区中文字幕| 亚洲天堂成人在线观看| 在线播放欧美女士性生活| 精品亚洲免费视频| 一区二区三区在线免费观看| 日韩一级二级三级精品视频| 粉嫩久久99精品久久久久久夜| 亚洲福利视频一区二区| 久久综合资源网| 欧美在线色视频| 国产美女一区二区| 亚洲高清视频中文字幕| 亚洲国产成人私人影院tom| 欧美久久久影院| 不卡一区中文字幕| 男人的天堂亚洲一区| 一区视频在线播放| xnxx国产精品| 欧美日本一道本| 91麻豆123| 国产xxx精品视频大全| 日韩av午夜在线观看| 亚洲精品中文在线| 国产日韩欧美高清在线| 欧美一二三四在线| 在线观看一区二区视频| 不卡av在线免费观看| 国产一区不卡在线| 免费在线观看一区| 午夜精品久久久久久不卡8050| 国产精品久线观看视频| 国产亚洲精品资源在线26u| 精品日韩在线观看| 欧美一区二区视频观看视频| 欧美少妇xxx| 欧美无砖专区一中文字| 99热在这里有精品免费| 国产成人亚洲综合a∨婷婷| 久久99国产精品免费网站| 日韩精品一卡二卡三卡四卡无卡| 亚洲人午夜精品天堂一二香蕉| 欧美高清在线一区| 国产精品色眯眯| 国产日产精品一区| 国产农村妇女精品| 国产欧美精品一区aⅴ影院 | 成人欧美一区二区三区白人| 日本一区二区成人| 久久久久久久性| 精品国产乱子伦一区| 2023国产精品视频| 久久人人爽人人爽| 国产欧美va欧美不卡在线| 国产日韩欧美a| 国产精品福利一区二区三区| 国产校园另类小说区| 久久精品视频在线看| 中文字幕在线一区| 亚洲欧美另类在线| 亚洲成av人片一区二区三区| 亚洲第一主播视频| 麻豆久久久久久久| 国产99一区视频免费| 99在线精品观看| 4438x亚洲最大成人网| 欧美一区二区女人| 欧美国产在线观看| 亚洲一区二区在线免费看| 日本欧美在线观看| 国产成人精品亚洲午夜麻豆| 91社区在线播放| 欧美日本一道本在线视频| 欧美一区二区久久| 国产清纯白嫩初高生在线观看91 | 青青草国产精品97视觉盛宴| 日本不卡1234视频| 国产一区日韩二区欧美三区| 成人国产亚洲欧美成人综合网| 日本高清不卡视频| 欧美成人乱码一区二区三区| 中文字幕日韩精品一区| 日韩国产精品久久久久久亚洲| 国产高清不卡二三区| 色猫猫国产区一区二在线视频| 91精品国产91久久综合桃花| 国产亚洲精品精华液| 午夜av区久久| 99久久婷婷国产综合精品| 日韩欧美一级片| 亚洲免费观看高清完整版在线观看| 日韩电影在线一区|