冒泡排序的Matlab版实现

tech2026-01-15  9

function [outputArg1,outputArg2] = Bubble(inputArg1,inputArg2) %BUBBLE 此处显示有关此函数的摘要 %   此处显示详细说明 % 冒泡排序第1次遍历后会将最大值放到最右边,这个最大值也是全局最大值。 sortarray=[3,5,1,-1,-7,4,9,-6,8,10,4]; [m,n]=size(sortarray); for i=1:n-1     for j=1:n-1         if sortarray(:,j)<sortarray(:,j+1)             a=sortarray(:,j);             sortarray(:,j)=sortarray(:,j+1);             sortarray(:,j+1)=a;         end     end end end

最新回复(0)