MATLAB冒泡法排序程序

冒泡法是经典排序算法, 顾名思义,就是把最小的数字像气泡一样往上冒,最终实现排序.

本程序为降序排序,也就是把最大值往上冒, MATLAB实现如下:

clc;close all;clear all;warning off;%清除变量

rand('seed', 100);

randn('seed', 100);

format long g;

disp('随机产生一个待排序数列');

timemat201=randi(3,20,10,1)

n2=size(timemat201,1);

tic;

state201=0;

while state201==0% 冒泡法

state201=1;

for i201=2:n2

t201=timemat201(i201-1,:);

t202=timemat201(i201,:);

if t201<t202

% 交换

timemat201(i201-1,:)=t202;

timemat201(i201,:)=t201;

state201=0;

end

end

end

toc

disp('排序后');

timemat201

程序结果:

相关推荐
不会就选b4 小时前
算法日常・每日刷题--<贪心>25
数据结构·算法
千里码aicood7 小时前
基于CART算法的图书分类系统设计与实现
数据库·算法·分类
做cv的小昊8 小时前
【World Model】π0.5:a Vision-Language-Action Model with Open-World Generalization
人工智能·算法·机器学习·大模型·多模态·vla·世界模型
لا معنى له8 小时前
World-In-World: World Models in a Closed-Loop World
算法
Discipline102911 小时前
尼泊尔河流流量:天气驱动的预测与高流量风险
人工智能·算法
XuCoder11 小时前
改一个数,右边全得重算,这题怎么扛住两万次查询
算法
小羊没烦恼!11 小时前
在Scrum中实施敏捷建模
java·开发语言·windows·算法·c#
weixin_3077791311 小时前
基于睿擎工业开发平台的预训练视觉模型轻量化适配与低代码部署优化
开发语言·算法
hold?fish:palm12 小时前
45 二叉树的右视图
开发语言·c++·算法