博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
quick sort(重复数版)
阅读量:6947 次
发布时间:2019-06-27

本文共 1187 字,大约阅读时间需要 3 分钟。

针对数组中有大量重复数优化

example

// 1,3,4,7,7,7,17,11,1,7

1 void QuickSort(int* arr, int from, int to); 2 void QSort(int* arr, int size); 3  4 void QuickSort(int* arr, int from, int to) 5 { 6     if(from >= to)    return; 7     int pivot = arr[to]; 8     // save the numbers of who's value equals pivot 9     int numsOfPivot = 0;10     int border = from;11 //                b     i12 //    1,3,4,7,7,7,17,11,1,713     for(int i = from; i <= to; i++)14     {15         if(arr[i] < pivot)16         {17             int temp = arr[i];18             arr[i] = arr[border];19             arr[border - numsOfPivot] = temp;20             ++border;21         }22         else if(arr[i] == pivot)23         {24             ++numsOfPivot;25             arr[i] = arr[border];26             ++border;27         }28     }29     // refill the duplicate of pivot at the behind of border30     while(numsOfPivot != 0)31     {32         arr[border-numsOfPivot] = pivot;33         --numsOfPivot;34     }35     QuickSort(arr,from,border-2-numsOfPivot);36     QuickSort(arr,border,to);37 }38 39 void QSort(int* arr, int size)40 {41     QuickSort(arr, 0, size-1);42 }

 

转载于:https://www.cnblogs.com/endenvor/p/9655350.html

你可能感兴趣的文章
swift知识点 [1]
查看>>
(转载)北上广深房价只会涨不会降
查看>>
移动存储卡仍然用FAT32文件系统的真相
查看>>
lambda 2
查看>>
windows下配置nginx+php环境
查看>>
Python批量读取人脸图片与数据互相转换
查看>>
android 75 新闻列表页面
查看>>
用数据说话:北京房价数据背后的数据
查看>>
Java系列笔记(4) - JVM监控与调优
查看>>
ITK 4.8.1 Qt 5.4 MinGW 4.9.1 Configuration 配置
查看>>
短网址算法原理
查看>>
kvm 性能调优
查看>>
OC 实例变量(Instance Var)和成员变量(member var)区别
查看>>
hdu 1542 Atlantis 段树区,并寻求,,,尼玛真坑人数据,不要打开一小阵!
查看>>
ssh 登录出现的几种错误以及解决办法
查看>>
Win7 OpenCV 3.0.0 VS2013 环境配置
查看>>
Deep Learning 深度学习 学习教程网站集锦(转)
查看>>
[转]"由于这台计算机没有远程桌面客户端访问许可证,远程会话被中断"的解决方案...
查看>>
构建自己的Java并发模型框架
查看>>
fusionchart实现ZoomLine 源码 破解版 能够导出
查看>>