前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数据结构与算法-快速排序算法

数据结构与算法-快速排序算法

作者头像
cwl_java
发布2019-11-18 13:05:44
2630
发布2019-11-18 13:05:44
举报
文章被收录于专栏:cwl_Javacwl_Java

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/weixin_42528266/article/details/103106305

代码示例
代码语言:javascript
复制
package com.cwl.arithmetic;

/**
 * @program: data-structure
 * @description: 快速排序
 * @author: ChenWenLong
 * @create: 2019-11-15 10:32
 **/
public class QuickSort {

    /**
     * 功能描述:
     * 〈对指定数组进行分割〉
     *
     * @params : [a, p, r]
     * @return : int
     * @author : cwl
     * @date : 2019/11/15 9:42
     */
    private static int partitionInt(int a[],int p,int r){
        int x = a[r-1];
        int i = p - 1;
        int temp;
        for(int j=p;j<=r-1;j++){
            if(a[j-1]<=x){
                i++;
                temp = a[j-1];
                a[j-1] = a[i-1];
                a[i-1] = temp;
            }
        }
        temp = a[r-1];
        a[r-1] = a[i];
        a[i] = temp;
        return i+1;
    }

    /**
     * 功能描述:
     * 〈快速排序方法〉
     *
     * @params : [a, p, r]
     * @return : void
     * @author : cwl
     * @date : 2019/11/15 9:42
     */
    public static void quickSortInt(int a[],int p,int r){
        if(p < r){
            int q = partitionInt(a, p, r);
            quickSortInt(a, p, q-1);
            quickSortInt(a, q+1, r);
        }
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-11-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 代码示例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档