简体   繁体   English

这是什么排序算法? (matlab中的代码)

[英]What kind of sorting algorithm is this? (Code in matlab)

I have a discussion with a teacher.我有一个老师的讨论。 He argues that the following algorithm corresponds to the bubble sort but I insist that it is not.他认为以下算法对应于冒泡排序,但我坚持认为它不是。 Who is right?谁是对的?

clc
clear

a=[0.2 4.333 1/3 5 7]

n=length(a)

for j=n:-1:1
for i=1:j-1
       if a(j)>a(i)
       else
            c=a(i);
            a(i)=a(j);
            a(j)=c;
            a
       end
end
end

This doesn't look like bubble sort as I understand it.据我了解,这看起来不像冒泡排序。 It starts from the final element, and compares it to each other element, swapping with the final element until the entire array has been run through, confirming that the largest number is at the end.它从最后一个元素开始,将它与其他元素进行比较,与最后一个元素交换,直到整个数组都跑完,确认最大的数字在最后。 Bubble sort compares numbers in adjacent pairs.冒泡排序比较相邻对中的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM