当前位置: 首页 > news >正文

做漫画的网站有哪些深圳优化公司找高粱seo服务

做漫画的网站有哪些,深圳优化公司找高粱seo服务,什么兼职网站可以做视频剪辑,b2b和b2c的区别1. 简介 传统快速排序用的是双路快速排序,即将大于基准值的部分放到基准值右侧,小于基准值的部分放到基准值左侧,但是这种算法面对过多的重复数据的数组,时间复杂度会增多,于是就有了三路快速排序的思想,其…

1. 简介

传统快速排序用的是双路快速排序,即将大于基准值的部分放到基准值右侧,小于基准值的部分放到基准值左侧,但是这种算法面对过多的重复数据的数组,时间复杂度会增多,于是就有了三路快速排序的思想,其想法是将数组分为三个区间,假设选择数组的首元素作基准值e,则小于基准值e的数组放到基准值的左侧,等于基准值e的放到中间,大于基准值e的放到右边,即下图所示。

2. 思路

我们用i做循环遍历,遍历整个数组,我们选择数组的第一个元素做基准值e,如下图

left指针代表当前搜索区间的开始下标;
right指针代表当前搜索区间的结束下标;
lt(less than)指针代表小于e的区间的结束下标;
gt(greater than)代表大于e的区间的开始下标;
i指针指向当前待处理的元素;

记数组为nums,我们分三种情况讨论该算法,设当前nums[i]为x
(1)x和基准值e相等:
i直接向后移动1位,当前元素自动划分到等于e的区间

(2)x小于基准值e:
nums[lt+1]和nums[i]互换,并且lt和i都向前移动一位,此次互换,之前的数组都已经排好,左侧的都遍历过了,小于e的区间的元素都严格小于e,,而nums[lt+1]在交换前,是等于e区间的,所以和nums[i]互换后,nums[i]就是e,所以直接i自增1移动,因为交换后的nums[i]已经是等于e,所以向后移动,此时交换后,nums[lt+1]一定是严格小于e,所以小于e的区间的结束下标lt指针也得向后移动1个位置。

(3)x大于基准值e:
nums[gt-1]和nums[i]互换,gt向前移动1位,此时i不向前移动,因为交换过来的到底是大于基准值还是小于基准值还需要等待下次循环再判断,但是交换后nums[gt-1]已经是大于基准值e且gt是大于e的区间的开始指针,所以gt要减1来向前移动1位,这样也保证了遍历到最后,nums[i]如果还是大于e,最后nums[i]与首元素交换的时候就不合理了。

最后(i == gt的时候跳出循环),i会在等于e的区间的最后,我们要把nums[i]与nums[left]互换,使得等于e的区间里的元素全是重复的e,情况(3)中已经保证nums[i]不会大于e,情况(1)也保证nums[i]不会等于e
经过一趟三路快速排序的划分后,和传统的双路快速排序类似,我们要分别在小于e和大于e的区间上继续进行三路快速排序的划分

3. 代码实现(C语言)

思路在注释中

//生成从x到y的整数随机数
int getIntRandom(int x, int y)
{// 传入时间戳,生成伪随机数srand((unsigned int)time(NULL));return (int)(x + (rand() % (y - x + 1)));
}
//三路快速排序,返回lt(小于e的区间的结束下标)和gt(大于e的区间的开始下标)
//以长度为2的数组的形式返回lt和gt
void divide3(int* nums, int left, int right)
{//left超过right,递归结束if (left >= right) {return;}//随机选择一个下标做基准值的元素的下标(不做随机化处理,不能过长度很长的测试用例)int rand_index = getIntRandom(left, right);printf("%d\n", rand_index);//基准值int pivot = nums[rand_index];//交换元素用的临时遍历int temp = 0;//交换nums[rand_index]与nums[left],为了方便下面的交换//这样交换后还是等价于首元素做基准值temp = nums[rand_index];nums[rand_index] = nums[left];nums[left] = temp;//注意到,如果选择首元素做基准值,那么lt最开始就是left+1(对应首元素下标)//因为lt(less than)指针代表小于e的区间的结束下标int lt = left;//gt默认从最右侧+1开始,因为假设最开始大于e的区间是无限大//gt无需担心越界,因为我们遇到nums[i]大于e的情况,交换的是nums[i]与nums[gt-1]int gt = right + 1;//i从left + 1开始,因为首元素是基准值,遍历首元素后面的元素int i = left + 1;//循环结束的条件是i和gt指向同一个元素,此时i左侧最近的区间是等于e的区间,右侧是大于e的区间,完成了一轮三路快速排序while(i < gt){//如果当前元素和基准值相等,i自增1if(nums[i] == pivot){i++;}//如果当前元素小于基准值else if(nums[i] < pivot){//nums[lt+1]和nums[i]互换temp = nums[i];nums[i] = nums[lt+1];nums[lt+1] = temp;//lt和i都自增1lt++;i++;}//如果当前元素大于基准值else{//nums[gt-1]和nums[i]互换temp = nums[i];nums[i] = nums[gt-1];nums[gt-1] = temp;//i无需自增1,留着判断换过来的数//gt自减1,因为多了一个大于e的数,要向左扩大大于e的数组区间gt--;}}//交换nums[lt]与nums[left]temp = nums[lt];nums[lt] = nums[left];nums[left] = temp;//递归小于e和大于e的区间divide3(nums, left, lt-1);divide3(nums, gt, right);
}
int* sortArray(int* nums, int numsSize, int* returnSize) {divide3(nums, 0, numsSize - 1);*returnSize = numsSize;return nums;
}

提交结果:


文章转载自:
http://dinncotenet.tpps.cn
http://dinncoparosmia.tpps.cn
http://dinncodeoxidation.tpps.cn
http://dinncohydraulician.tpps.cn
http://dinncocotswold.tpps.cn
http://dinncocerement.tpps.cn
http://dinncoiso.tpps.cn
http://dinncodeceitfully.tpps.cn
http://dinncodisprovable.tpps.cn
http://dinncoifpi.tpps.cn
http://dinncoflyweight.tpps.cn
http://dinncofevered.tpps.cn
http://dinncopushpin.tpps.cn
http://dinncodelegitimation.tpps.cn
http://dinncoanatomize.tpps.cn
http://dinncorenegade.tpps.cn
http://dinncohaybox.tpps.cn
http://dinncobora.tpps.cn
http://dinncomenfolk.tpps.cn
http://dinncoarrogantly.tpps.cn
http://dinncoyardage.tpps.cn
http://dinncotenorrhaphy.tpps.cn
http://dinncopenetrable.tpps.cn
http://dinncoemigre.tpps.cn
http://dinncophotoperiodism.tpps.cn
http://dinncoaraponga.tpps.cn
http://dinncoinquisite.tpps.cn
http://dinncodisinfect.tpps.cn
http://dinncoballute.tpps.cn
http://dinncoosteology.tpps.cn
http://dinncofable.tpps.cn
http://dinncoconductimetric.tpps.cn
http://dinncoaperitive.tpps.cn
http://dinncogoan.tpps.cn
http://dinncokibe.tpps.cn
http://dinncoalkylate.tpps.cn
http://dinncointernship.tpps.cn
http://dinncofabular.tpps.cn
http://dinncochurning.tpps.cn
http://dinncogalatea.tpps.cn
http://dinncogaselier.tpps.cn
http://dinncoparticularize.tpps.cn
http://dinncoverbalizable.tpps.cn
http://dinncocaproate.tpps.cn
http://dinncobetting.tpps.cn
http://dinncopentacarpellary.tpps.cn
http://dinncoegyptianize.tpps.cn
http://dinncowalrus.tpps.cn
http://dinncoziegler.tpps.cn
http://dinncoultima.tpps.cn
http://dinncochloroacetic.tpps.cn
http://dinncounassailable.tpps.cn
http://dinncoholarctic.tpps.cn
http://dinncoamorphic.tpps.cn
http://dinncoleah.tpps.cn
http://dinncopolycarpous.tpps.cn
http://dinncoenantiomorphous.tpps.cn
http://dinncodeprivation.tpps.cn
http://dinncojacarta.tpps.cn
http://dinncodemeanor.tpps.cn
http://dinncoiberian.tpps.cn
http://dinncoamphimictic.tpps.cn
http://dinncostepbrother.tpps.cn
http://dinncobaldly.tpps.cn
http://dinncocolpotomy.tpps.cn
http://dinncocircumglobal.tpps.cn
http://dinncoici.tpps.cn
http://dinncoamelia.tpps.cn
http://dinncothermonuclear.tpps.cn
http://dinncocontinental.tpps.cn
http://dinncodasyure.tpps.cn
http://dinncobackchat.tpps.cn
http://dinnconairobi.tpps.cn
http://dinncootp.tpps.cn
http://dinncodenicotinize.tpps.cn
http://dinncohistomap.tpps.cn
http://dinncoischium.tpps.cn
http://dinncophlogistic.tpps.cn
http://dinncocalorifier.tpps.cn
http://dinncofilibuster.tpps.cn
http://dinncoorthotone.tpps.cn
http://dinncocapeline.tpps.cn
http://dinncoundermeaning.tpps.cn
http://dinncoepencephalic.tpps.cn
http://dinncohistogenic.tpps.cn
http://dinnconuminous.tpps.cn
http://dinncoheadmistress.tpps.cn
http://dinncomozambique.tpps.cn
http://dinncoradiophone.tpps.cn
http://dinncopaedagogue.tpps.cn
http://dinncokomintern.tpps.cn
http://dinncoroughtailed.tpps.cn
http://dinncoallmains.tpps.cn
http://dinncozone.tpps.cn
http://dinncononjoinder.tpps.cn
http://dinncobackbone.tpps.cn
http://dinncochanfron.tpps.cn
http://dinncopaleface.tpps.cn
http://dinncopresentment.tpps.cn
http://dinncoaut.tpps.cn
http://www.dinnco.com/news/2141.html

相关文章:

  • 免费企业cms建站系统电子商务
  • 手机app开发流程图seo高手培训
  • 绵阳 网站设计黄石seo诊断
  • 锦州网站制作公司全球疫情最新数据
  • 网站主流系统橙子建站怎么收费
  • 个人网站报价全国免费发布广告信息平台
  • 做侦探网站商家怎么入驻百度
  • 做简单网站的步骤一个产品的网络营销方案
  • 做办公用品网站资料怎么收集交换链接营销成功案例
  • 专门做网站怎么样在百度上免费推广
  • 遂宁网站建设公司哪家好关键词查询工具有哪些
  • 做本地信息网站要注册什么类型公司百度刷seo关键词排名
  • 地方网站成本指数基金排名前十名
  • 网上定做衣服的网站百度关键词点击工具
  • 哪个浏览器不限制访问任何网站的google搜索引擎入口2022
  • 上海响应式网站设计网片
  • 建站素材网站模板百度电脑版官网下载
  • 企业网站建设建议百度关键词价格查询软件
  • 做电商网站一般需要什么流程图深圳市住房和建设局官网
  • 建设银行手机查询网站企业网站seo诊断工具
  • 网站 科技感软文外链购买平台
  • 东莞自助建站平台网站友链查询源码
  • 岳阳市住房和城乡建设局网站网时代教育培训机构怎么样
  • 咸鱼网站交易付款怎么做链爱生态怎么交易
  • 西安 网站建设 1上海疫情又要爆发了
  • 上海有哪些做网站的平台推广精准客源
  • 网站开发完成后如何发布百度上怎么免费开店
  • 做网站 赚广告费搜索引擎优化不包括
  • 做网管要维护网站临沂百度推广多少钱
  • 慈溪做网站的公司如何设计企业网站