Can help me create a selection sort function? I understand how it works but I cant come up with a code that works.
2 次查看(过去 30 天)
显示 更早的评论
here is what i have
function y = Mekuluselect(x)
n = length(x);
C = 0; S = 0;
for k = 1:n
C = C + 1;
m = k;
if x(k) < x(m)
temp = x(k);
x(k) = x(m);
x(m) = temp;
S = S + 1;
end
end
y = x;
end
2 个评论
Walter Roberson
2013-10-19
What happens when you try your code? Does it give an error message? Always? Sometimes? Which arrays does it fail on?
回答(1 个)
Azzi Abdelmalek
2013-10-19
编辑:Azzi Abdelmalek
2013-10-19
Look at this line
m = k;
if x(k) < x(m)
this expression is always false, which means your code does nothing
Also we can notice that C is not used by your code
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!