快排

一、快排基本原理

       自己search一下吧。

二、递归实现

       自己动手,试一试;

 

 

/********************************************************
说明:
    该文件实现快排序

    涉及的内容:
        1. 快排序;

测试环境:
    1. Linux 2.6.18-348.el5 #1 SMP 24core.

测试结果:
[root@dell38 app]# time ./quickSort1 1200000000
Gen rand number :1200000000 ...
       Gen over:604289383 846930886 481692777 514636915 757747793 424238335 719885386 449760492 596516649 1189641421 1025202362 150490027 783368690 1102520059 844897763 767513926 165180540 340383426 304089172 103455736 35005211 521595368 294702567 526956429 336465782 861021530 278722862 233665123 945174067 468703135 1101513929 601979802 115634022 635723058 169133069 1125898167 1059961393 889018456 628175011 456478042 1131176229 453377373 859484421 714544919 608413784 756898537 534575198 773594324 149798315 838664370 1129566413 184803526 412776091 224268980 711759956 749241873 137806862 42999170 982906996 135497281 511702305 884420925 737477084 627336327 572660336 1159126505 805750846 432621729 1100661313 233925857 1141616124 84353895 939819582 801100545 798898814 348233367 610515434 385990364 174344043 760313750 277171087 356426808 945117276 689947178 580695788 709393584 491705403 718502651 752392754 274612399 853999932 64095060 211549676 643993368 943947739 784210012 855636226 549698586 269348094 756297539 1036140795 463480570 840651434 775960378 317097467 692066601 176710097 927612902 130573317 603570492 487926652 660260756 959997301 485560280 402724286 593209441 1194953865 894429689 364228444 747346619 
Quick sort 1200000000 number...
=================================
     After sort:  1   2   3   3   4   5   7   8   9   9   9   9  10  11  11  11  12  14  15  16  17  17  17  19  19  21  23  24  24  26  27  27  27  28  31  31  31  32  33  33  35  37  38  38  38  39  40  40  41  42  42  44  44  44  44  45  46  46  47  48  50  50  50  51  52  52  52  53  54  55  55  56  58  58  58  59  59  60  60  63  64  64  66  67  67  67  67  68  71  71  72  74  75  75  76  77  77  79  79  83  83  84  84  84  85  89  89  92  93  94  95  95  96  96  97  97  99  99 100 101 
Check over. [errer counter:0; loop:814552250]

real    4m0.132s
user    3m55.838s
sys     0m1.580s

说明:递归实现,当数据量增加后,递归调用栈太深,效率低。
     上面排序12亿数据大概要3分钟左右;


2014.11.12 Aming created. 
*********************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef int arrary_t;

#define arrary_value(a) (*a)

int loop = 0;

#if 0
#define ARRARY_LEN 25

arrary_t arrary[ARRARY_LEN] = {70,  80,  2,  40, 100,
                               22,  21, 77,  68, 75,
                               90,  94, 31,  33, 17,
                               101, 15, 16, 123, 43,
                               44,  48, 65,   7, 200};
#elif 0
#define ARRARY_LEN 2180

arrary_t arrary[ARRARY_LEN] = {70,  80,  2,  40, 100,  1,  2,  3,  4,  5,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                                70,  80,  2,  40, 100,  1,  2,  3,  4,  5,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23,
                               22,  21, 77,  68, 75,   6,  7,  8,  9, 10,
                               90,  21, 77,  33, 17, 333, 23, 465, 9, 20,
                               101, 21, 77, 123, 43, 77,  33, 17, 333, 23                               };
#else
#define ARRARY_MALLOC_TRUE 
#ifdef ARRARY_MALLOC_TRUE
//#define ARRARY_LEN (1024*1024*1024)
//#define ARRARY_LEN (50000000)
int ARRARY_LEN = 5000000;
arrary_t *arrary;
#endif
#endif

arrary_t *gen_rand_arrary(void)
{
    int i;

    arrary_t *a;
    
    a = (arrary_t *)malloc(sizeof(arrary_t)*ARRARY_LEN);
    if (NULL == a)
    {
        printf("Malloc error.\n");
        return NULL;
    }

    for (i = 0; i < ARRARY_LEN; i++)
    {
        #if 1
        a[i]  = rand()%ARRARY_LEN;
        #elif 0
        a[i]  = rand();
        #else
        a[i]  = ARRARY_LEN - i;
        #endif
    }
    
    return a;
}

int quick_sort_d(arrary_t *left, arrary_t *right)
{
    printf("left:%p\n", left);    
    printf("right:%p\n", right);    

    return 0;
}

void show_arrary(char *prefix, arrary_t *arrary, arrary_t *low, arrary_t *up)
{
    int i;
    printf("%16s", prefix);
    for (i = 0; i < ARRARY_LEN; i++)
    {
        if ((NULL != up)||(NULL != low))
        {
            if (arrary[i] == *up)
                printf("%3dup ", arrary[i]);
            else if (arrary[i] == *low)
                printf("%3dlow", arrary[i]);
            else
                printf("%3d   ", arrary[i]);
        }
        else 
        {
            printf("%3d ", arrary[i]);
        }
    }
    //printf("\n");
    
    return ;
}
void show_arrary1(char *prefix, arrary_t *arrary, int show_num)
{
    int i;
    printf("%16s", prefix);
    for (i = 0; i < show_num; i++)
    {
        printf("%3d ", arrary[i]);
    }
    
    return ;
}
void check_result(arrary_t *arrary)
{
    arrary_t * p1 = arrary;
    arrary_t * p2 = arrary + 1;

    int counter = ARRARY_LEN;
    int err_counter = 0;

    while (counter > 1)
    {
        if (*p1 > *p2)
        {
            printf("p1:%d > p2:%d\n", *p1, *p2);
            err_counter++;
        }

        p1++;
        p2++;
        counter--;
    }

    printf("\nCheck over. [errer counter:%d; loop:%d]\n", err_counter, loop);

    return;
}
int quick_sort(arrary_t *left, arrary_t *right)
{
    loop++;
    //printf("loop:%d left:%d, right:%d->\n", loop++, *left, *right);    

    //if (loop > 1)
    //    return 0;
    
    int ret = 0;
    arrary_t center;
    arrary_t *low = left;
    arrary_t *up  = right;

    if ((NULL == left) || (NULL == right))
    {
        return -1;
    }
    
    if (left == right)
    {
        printf("~~~~~~~~~~~~end.\n");
        return 0;
    }

    center = arrary_value(low);

    while (low != up)
    {
        //printf("low:%3d, up:%3d ", *low, *up);    
        //show_arrary("arrary:", arrary, low, up);printf("\n");
        
        if (arrary_value(low) == center)
        {
            if (arrary_value(low) < arrary_value(up))
            {
                up--;
            }
            else if (arrary_value(low) > arrary_value(up))
            {
                arrary_value(low) = arrary_value(up);
                arrary_value(up)  = center;
                low++;
            }
            else //(arrary_value(low) == arrary_value(up))
            {
                up--;
            }
        }
        else //(arrary_value(up) == center)
        {
            if (arrary_value(low) < arrary_value(up))
            {
                low++;
            }
            else if (arrary_value(low) > arrary_value(up))
            {
                arrary_value(up)  = arrary_value(low);  
                arrary_value(low) = center;
                up--;
            }
            else //(arrary_value(low) == arrary_value(up))
            {
                low++;
            }        
        }
        
        //show_arrary("arrary:", arrary, low, up);printf("\n");

        continue;
    }//end while


    if ((low - left) > 1)
    {
        ret = quick_sort(left, low-1);
        if (0 != ret)
        {
            printf("error.\n");
            return ret;
        }
    }

    if ((right - up) > 1)
    {
        ret = quick_sort(up + 1, right);
        if (0 != ret)
        {
            printf("error.\n");
            return ret;
        }
    }

    return 0;
}


#define SHOW_NUMBER 120
int main(int argc, char ** argv)
{
    int ret = 0;
    int i;

    (void)i;

    if (argc >= 2)
    {
        ARRARY_LEN = atoi(argv[1]);
    }

    #ifdef ARRARY_MALLOC_TRUE
    printf("Gen rand number :%d ...\n", ARRARY_LEN);
    arrary = gen_rand_arrary();
    if (NULL == arrary)
    {
        printf("[fun:%s, line:%d] error.\n", __FUNCTION__, __LINE__);
        return -1;
    }
    
    show_arrary1("Gen over:", arrary, ((SHOW_NUMBER>ARRARY_LEN)? ARRARY_LEN : SHOW_NUMBER));
    #endif

    printf("\nQuick sort %d number...\n", ARRARY_LEN);
    //show_arrary("Before sort: ", arrary, NULL, NULL); printf("\n");

    ret = quick_sort(arrary, (arrary + ARRARY_LEN -1));
    if (0 != ret)
    {
        printf("[fun:%s, line:%d] error.\n", __FUNCTION__, __LINE__);
        return ret;
    }
    
    //show_arrary("After sort: ", arrary, NULL, NULL);printf("\n");
    printf("=================================\n");
    show_arrary1("After sort:", arrary, ((SHOW_NUMBER>ARRARY_LEN) ? ARRARY_LEN : SHOW_NUMBER));
    check_result(arrary);

    #ifdef ARRARY_MALLOC_TRUE
    free(arrary);
    #endif
    
    return 0;
}


 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值