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

程序结果:

相关推荐
Navigator_Z9 分钟前
LeetCode //C - 1288. Remove Covered Intervals
c语言·算法·leetcode
码爸25 分钟前
决策树介绍与示例
python·算法·机器学习
动词ing1 小时前
【题目练习】字符串相乘
算法
0+1111 小时前
算法 --链表
数据结构·算法·leetcode·链表
aqiu1111111 小时前
【C++算法打怪专栏】C++ `unordered_set` 常用初始化与插入方法总结
开发语言·c++·算法
Terra.K2 小时前
高精度阶乘求和模板深度解析
开发语言·c++·算法
Peregrine92 小时前
C++ - > 类和对象
java·c++·算法
Gigavision3 小时前
DEAP数据集 2026最新Transformer算法 DEAP 数据集 下载
深度学习·算法·transformer
夜之眷属4 小时前
PriorityQueue:for-each 遍历和 poll 取出,顺序一样吗?
java·服务器·数据结构·后端·算法
地平线开发者4 小时前
不是线程越多越快:用 hrt_model_exec 在 征程6M 上给 YOLOv5x 建立性能基线
算法