我是靠谱客的博主 俭朴哈密瓜,这篇文章主要介绍matlab快速排序,现在分享给大家,希望可以做个参考。

function [ A ] = quickSort( A,p,r )
%UNTITLED5 Summary of this function goes here
%   Detailed explanation goes here
if p<r
    [A,q]=partition(A,p,r);
    A=quickSort(A,p,q-1);
    A=quickSort(A,q+1,r);
end


end


function [ A,q ] = partition( A,p,r )
%UNTITLED6 Summary of this function goes here
%   Detailed explanation goes here
x=A(r);
i=p-1;
for j=p:r-1
    if A(j)<=x
        i=i+1;
        temp=A(j);
        A(j)=A(i);
        A(i)=temp;
    end
end
 temp=A(i+1);
 A(i+1)=A(r);
 A(r)=temp;
q=i+1;


end


最后

以上就是俭朴哈密瓜最近收集整理的关于matlab快速排序的全部内容,更多相关matlab快速排序内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部