필터 지우기
필터 지우기

Can help me create a selection sort function? I understand how it works but I cant come up with a code that works.

조회 수: 1 (최근 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
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
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

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by