[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
快速排序
public class sort { public static void main(String[] args){ int
arr[]={59,6,3,8,51,23}; QuickSort(arr,0,arr.length-1);
System.out.println(Arrays.toString(arr)); } public static void QuickSort(int[]
arr,int left,int right){ //递归出口 if(left>=right){ return; } //定义变量保存基准数 int base
= arr[left]; //定义变量i指向最左边(目的是每一轮中) int i = left; //定义变量j指向最右边(目的是每一轮中) int j =
right; //当i和j没有相遇的时候,执行循环 while(i<j){ //j从最右边检索比基准数小的,当检索到了就停下
while(arr[j]>=base&&i<j){ j--; } //i从最左边检索比基准数大的,当检索到了就停下
while(arr[i]<=base&&i<j){ i++; } //检索到的两个数交换 int temp = arr[j]; arr[j]=arr[i];
arr[i]=temp; } //指针重合的位置i上的数和基准数交换 arr[left]=arr[i]; arr[i]=base; //排基准数左边
QuickSort(arr,left,i-1); //排基准数右边 QuickSort(arr,i+1,right); } }
快速排序思想:
通过一趟排序将待排记录分隔成独立的两部分,其中一部分记录的关键字均比另一部分的关键字小,则可以分别对这两部分记录继续进行排序,以达到整个序列有序
快速排序法使用分治法来吧一个串分为两个字串
1.会把数组当中的一个树当作基准数
2.一般会把数组中最左边的树当作基准数,然后从两边进行检索。从右边检索比基准数小的,然后左边检索比基准数大的。如果检索到了,就停下,然后交换这两个元素,然后继续检索
1.首先找到一个基准数base=5
2.先移动右边的指针j,找到第一个小于5的数,也就是1
然后在移动左边的指针i,找到第一个大于5的数,也就是6
然后进行交换
3.i和j一旦相遇,就停止检索把基准数和相遇位置的数进行交换
4.第一次排序完毕,排序完成以后我们发现排序左边的数比基准数小,右边比基准数大
把左右两边的数据都看成一个新的数组,那么这个数组和原来的数会经历相同的方式进行排序
分析递归表达式和递归出口