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

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

?? qsort.c

?? C標準庫源代碼,能提高對C的理解,不錯的哦
?? C
字號:
/***
*qsort.c - quicksort algorithm; qsort() library function for sorting arrays
*
*       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
*       To implement the qsort() routine for sorting arrays.
*
*******************************************************************************/

#include <cruntime.h>
#include <stdlib.h>
#include <search.h>

/* prototypes for local routines */
static void __cdecl shortsort(char *lo, char *hi, unsigned width,
                int (__cdecl *comp)(const void *, const void *));
static void __cdecl swap(char *p, char *q, unsigned int width);

/* this parameter defines the cutoff between using quick sort and
   insertion sort for arrays; arrays with lengths shorter or equal to the
   below value use insertion sort */

#define CUTOFF 8            /* testing shows that this is good value */


/***
*qsort(base, num, wid, comp) - quicksort function for sorting arrays
*
*Purpose:
*       quicksort the array of elements
*       side effects:  sorts in place
*
*Entry:
*       char *base = pointer to base of array
*       unsigned num  = number of elements in the array
*       unsigned width = width in bytes of each array element
*       int (*comp)() = pointer to function returning analog of strcmp for
*               strings, but supplied by user for comparing the array elements.
*               it accepts 2 pointers to elements and returns neg if 1<2, 0 if
*               1=2, pos if 1>2.
*
*Exit:
*       returns void
*
*Exceptions:
*
*******************************************************************************/

/* sort the array between lo and hi (inclusive) */

void __cdecl qsort (
    void *base,
    unsigned num,
    unsigned width,
    int (__cdecl *comp)(const void *, const void *)
    )
{
    char *lo, *hi;              /* ends of sub-array currently sorting */
    char *mid;                  /* points to middle of subarray */
    char *loguy, *higuy;        /* traveling pointers for partition step */
    unsigned size;              /* size of the sub-array */
    char *lostk[30], *histk[30];
    int stkptr;                 /* stack for saving sub-array to be processed */

    /* Note: the number of stack entries required is no more than
       1 + log2(size), so 30 is sufficient for any array */

    if (num < 2 || width == 0)
        return;                 /* nothing to do */

    stkptr = 0;                 /* initialize stack */

    lo = base;
    hi = (char *)base + width * (num-1);        /* initialize limits */

    /* this entry point is for pseudo-recursion calling: setting
       lo and hi and jumping to here is like recursion, but stkptr is
       prserved, locals aren't, so we preserve stuff on the stack */
recurse:

    size = (hi - lo) / width + 1;        /* number of el's to sort */

    /* below a certain size, it is faster to use a O(n^2) sorting method */
    if (size <= CUTOFF) {
         shortsort(lo, hi, width, comp);
    }
    else {
        /* First we pick a partititioning element.  The efficiency of the
           algorithm demands that we find one that is approximately the
           median of the values, but also that we select one fast.  Using
           the first one produces bad performace if the array is already
           sorted, so we use the middle one, which would require a very
           wierdly arranged array for worst case performance.  Testing shows
           that a median-of-three algorithm does not, in general, increase
           performance. */

        mid = lo + (size / 2) * width;      /* find middle element */
        swap(mid, lo, width);               /* swap it to beginning of array */

        /* We now wish to partition the array into three pieces, one
           consisiting of elements <= partition element, one of elements
           equal to the parition element, and one of element >= to it.  This
           is done below; comments indicate conditions established at every
           step. */

        loguy = lo;
        higuy = hi + width;

        /* Note that higuy decreases and loguy increases on every iteration,
           so loop must terminate. */
        for (;;) {
            /* lo <= loguy < hi, lo < higuy <= hi + 1,
               A[i] <= A[lo] for lo <= i <= loguy,
               A[i] >= A[lo] for higuy <= i <= hi */

            do  {
                loguy += width;
            } while (loguy <= hi && comp(loguy, lo) <= 0);

            /* lo < loguy <= hi+1, A[i] <= A[lo] for lo <= i < loguy,
               either loguy > hi or A[loguy] > A[lo] */

            do  {
                higuy -= width;
            } while (higuy > lo && comp(higuy, lo) >= 0);

            /* lo-1 <= higuy <= hi, A[i] >= A[lo] for higuy < i <= hi,
               either higuy <= lo or A[higuy] < A[lo] */

            if (higuy < loguy)
                break;

            /* if loguy > hi or higuy <= lo, then we would have exited, so
               A[loguy] > A[lo], A[higuy] < A[lo],
               loguy < hi, highy > lo */

            swap(loguy, higuy, width);

            /* A[loguy] < A[lo], A[higuy] > A[lo]; so condition at top
               of loop is re-established */
        }

        /*     A[i] >= A[lo] for higuy < i <= hi,
               A[i] <= A[lo] for lo <= i < loguy,
               higuy < loguy, lo <= higuy <= hi
           implying:
               A[i] >= A[lo] for loguy <= i <= hi,
               A[i] <= A[lo] for lo <= i <= higuy,
               A[i] = A[lo] for higuy < i < loguy */

        swap(lo, higuy, width);     /* put partition element in place */

        /* OK, now we have the following:
              A[i] >= A[higuy] for loguy <= i <= hi,
              A[i] <= A[higuy] for lo <= i < higuy
              A[i] = A[lo] for higuy <= i < loguy    */

        /* We've finished the partition, now we want to sort the subarrays
           [lo, higuy-1] and [loguy, hi].
           We do the smaller one first to minimize stack usage.
           We only sort arrays of length 2 or more.*/

        if ( higuy - 1 - lo >= hi - loguy ) {
            if (lo + width < higuy) {
                lostk[stkptr] = lo;
                histk[stkptr] = higuy - width;
                ++stkptr;
            }                           /* save big recursion for later */

            if (loguy < hi) {
                lo = loguy;
                goto recurse;           /* do small recursion */
            }
        }
        else {
            if (loguy < hi) {
                lostk[stkptr] = loguy;
                histk[stkptr] = hi;
                ++stkptr;               /* save big recursion for later */
            }

            if (lo + width < higuy) {
                hi = higuy - width;
                goto recurse;           /* do small recursion */
            }
        }
    }

    /* We have sorted the array, except for any pending sorts on the stack.
       Check if there are any, and do them. */

    --stkptr;
    if (stkptr >= 0) {
        lo = lostk[stkptr];
        hi = histk[stkptr];
        goto recurse;           /* pop subarray from stack */
    }
    else
        return;                 /* all subarrays done */
}


/***
*shortsort(hi, lo, width, comp) - insertion sort for sorting short arrays
*
*Purpose:
*       sorts the sub-array of elements between lo and hi (inclusive)
*       side effects:  sorts in place
*       assumes that lo < hi
*
*Entry:
*       char *lo = pointer to low element to sort
*       char *hi = pointer to high element to sort
*       unsigned width = width in bytes of each array element
*       int (*comp)() = pointer to function returning analog of strcmp for
*               strings, but supplied by user for comparing the array elements.
*               it accepts 2 pointers to elements and returns neg if 1<2, 0 if
*               1=2, pos if 1>2.
*
*Exit:
*       returns void
*
*Exceptions:
*
*******************************************************************************/

static void __cdecl shortsort (
    char *lo,
    char *hi,
    unsigned width,
    int (__cdecl *comp)(const void *, const void *)
    )
{
    char *p, *max;

    /* Note: in assertions below, i and j are alway inside original bound of
       array to sort. */

    while (hi > lo) {
        /* A[i] <= A[j] for i <= j, j > hi */
        max = lo;
        for (p = lo+width; p <= hi; p += width) {
            /* A[i] <= A[max] for lo <= i < p */
            if (comp(p, max) > 0) {
                max = p;
            }
            /* A[i] <= A[max] for lo <= i <= p */
        }

        /* A[i] <= A[max] for lo <= i <= hi */

        swap(max, hi, width);

        /* A[i] <= A[hi] for i <= hi, so A[i] <= A[j] for i <= j, j >= hi */

        hi -= width;

        /* A[i] <= A[j] for i <= j, j > hi, loop top condition established */
    }
    /* A[i] <= A[j] for i <= j, j > lo, which implies A[i] <= A[j] for i < j,
       so array is sorted */
}


/***
*swap(a, b, width) - swap two elements
*
*Purpose:
*       swaps the two array elements of size width
*
*Entry:
*       char *a, *b = pointer to two elements to swap
*       unsigned width = width in bytes of each array element
*
*Exit:
*       returns void
*
*Exceptions:
*
*******************************************************************************/

static void __cdecl swap (
    char *a,
    char *b,
    unsigned width
    )
{
    char tmp;

    if ( a != b )
        /* Do the swap one character at a time to avoid potential alignment
           problems. */
        while ( width-- ) {
            tmp = *a;
            *a++ = *b;
            *b++ = tmp;
        }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久久久97三级| 欧美在线看片a免费观看| 亚洲精品成a人| 国产欧美精品一区| 日韩一区二区三区高清免费看看| 色欧美乱欧美15图片| jiyouzz国产精品久久| 国产精品一二三区在线| 亚洲欧美偷拍另类a∨色屁股| 欧美成人精精品一区二区频| 91丨九色丨尤物| 久久精品国产99国产精品| 日本欧美在线观看| 免费在线看一区| 日韩一区欧美二区| 日韩精品电影在线观看| 午夜视频在线观看一区二区三区| 一区二区三区在线免费视频| 亚洲欧洲在线观看av| 亚洲色图都市小说| 亚洲精品福利视频网站| 日韩美女视频一区| 亚洲一区在线观看视频| 亚洲成人综合在线| 捆绑调教一区二区三区| 国产专区综合网| 蜜臀av性久久久久av蜜臀妖精 | 国产精品白丝在线| 国产精品激情偷乱一区二区∴| 欧美激情自拍偷拍| 亚洲免费观看在线观看| 亚洲最大成人综合| 同产精品九九九| 国产一区二区三区香蕉| 成人一级片在线观看| 99国产精品久久久久| 91麻豆文化传媒在线观看| 91视频一区二区三区| 在线观看中文字幕不卡| 日韩欧美国产成人一区二区| 26uuu精品一区二区| 欧美韩国日本综合| 亚洲国产日韩a在线播放| 全国精品久久少妇| 不卡欧美aaaaa| 欧美日韩精品一区二区| 2023国产一二三区日本精品2022| 6080国产精品一区二区| 日韩三级视频中文字幕| 国产午夜精品久久久久久免费视| 亚洲色图.com| 久久99最新地址| 色哟哟精品一区| 亚洲精品一区二区三区福利| ...xxx性欧美| 激情欧美一区二区三区在线观看| 91在线精品一区二区三区| 欧美成人猛片aaaaaaa| 亚洲视频一区二区免费在线观看| 免费成人小视频| 91最新地址在线播放| 精品国产乱码91久久久久久网站| 综合中文字幕亚洲| 国模大尺度一区二区三区| 欧美日韩亚洲综合在线 欧美亚洲特黄一级| 91精品国产乱码| 自拍偷拍欧美精品| 国产成人自拍网| 91精品婷婷国产综合久久 | 丁香网亚洲国际| 91精品中文字幕一区二区三区| 国产精品夫妻自拍| 激情综合色综合久久| 3atv一区二区三区| 亚洲一二三区不卡| 色www精品视频在线观看| 91精品国产综合久久精品图片 | 毛片基地黄久久久久久天堂| 欧美视频日韩视频在线观看| 综合分类小说区另类春色亚洲小说欧美| 精品一区二区精品| 91精品国产全国免费观看| 亚洲一级在线观看| 欧美系列一区二区| 亚洲综合一区二区三区| 一本大道综合伊人精品热热| 国产亚洲污的网站| 国产福利电影一区二区三区| 精品盗摄一区二区三区| 麻豆精品精品国产自在97香蕉| 欧美夫妻性生活| 日日夜夜免费精品视频| 91精品视频网| 亚洲线精品一区二区三区| 岛国一区二区三区| 日韩视频永久免费| 麻豆国产欧美一区二区三区| 91婷婷韩国欧美一区二区| 久久久久久久久久久久电影| 国产美女主播视频一区| 久久色在线观看| 东方欧美亚洲色图在线| 一区视频在线播放| 欧美亚洲综合久久| 日本vs亚洲vs韩国一区三区二区 | 午夜精品一区二区三区免费视频| 欧美性感一区二区三区| 午夜视频一区二区| 精品卡一卡二卡三卡四在线| 国产乱码精品一品二品| 国产精品国产三级国产| 色av综合在线| 三级在线观看一区二区| 久久久久久一级片| 91在线一区二区三区| 日韩电影网1区2区| 久久久久久久综合色一本| 成人av综合一区| 亚洲电影中文字幕在线观看| 日韩一区二区三区视频在线| 乱一区二区av| 亚洲国产精品成人综合| 精品视频在线免费观看| 日韩精品每日更新| 国产精品免费久久| 欧美日韩国产小视频| 国产一区二区三区四区五区美女 | 国产91丝袜在线播放| 亚洲精品高清在线| 26uuu精品一区二区三区四区在线| 成人美女在线观看| 午夜国产精品影院在线观看| 久久久久成人黄色影片| 欧美日韩在线电影| 国产99久久精品| 午夜成人免费电影| 中文字幕亚洲欧美在线不卡| 欧美成人一区二区三区| 精品在线播放午夜| 久久影院电视剧免费观看| 91国模大尺度私拍在线视频| 国产一区二区美女| 五月天亚洲精品| 日韩美女精品在线| 欧美国产精品中文字幕| 久久一留热品黄| 欧美巨大另类极品videosbest| 99久久久精品| 国产九色精品成人porny| 日本中文字幕不卡| 亚洲一区二区视频| 亚洲日韩欧美一区二区在线| 久久蜜桃av一区二区天堂 | 亚洲欧美在线观看| 欧美最猛性xxxxx直播| 波多野结衣亚洲| 青草国产精品久久久久久| 久久久久久久网| 欧美一级国产精品| 欧美日韩精品一区视频| 在线观看亚洲一区| 91蜜桃免费观看视频| 成人黄色一级视频| 国产成人精品亚洲午夜麻豆| 国产一区二区中文字幕| 激情综合网av| 韩国av一区二区| 国产成人亚洲综合色影视| 国产在线一区二区综合免费视频| 美女高潮久久久| 精品制服美女久久| 国产精品一级在线| 国产91丝袜在线18| 99久久久精品| 欧美亚洲综合网| 91麻豆精品国产91久久久资源速度| 欧日韩精品视频| 91麻豆精品国产91久久久使用方法| 色婷婷精品大在线视频 | 日韩精品电影一区亚洲| 亚洲国产经典视频| 久久久久亚洲综合| 日韩理论片在线| 亚洲毛片av在线| 麻豆精品一二三| 不卡在线视频中文字幕| 色噜噜狠狠色综合中国| 欧美理论电影在线| 国产欧美精品区一区二区三区 | 欧美亚洲国产一区二区三区va| 欧美剧在线免费观看网站 | 91久久线看在观草草青青| 精品婷婷伊人一区三区三| 久久美女艺术照精彩视频福利播放 | 欧美在线免费播放| 国产亚洲短视频| 日韩电影在线观看一区| 成人激情开心网| 精品美女一区二区三区| 亚洲国产你懂的|