How to write this pseudocode in matlab?
이전 댓글 표시
a=[5,9,13,2,7,10,4,8,11,1];
int phase, x, t;
for (phase=0; phase<n; phase++)
if(phase%2 ==0)
{
for(x=1;x<n;x+=2)
if(a[x-1]>a[x])
{
t=a[x];
a[x]=a[x-1];
a[x-1]=t;
}
end
end
}
else
{
for(x=1; x<n-1; x +=2)
if(a[x]>a[x+1])
{
t=a[x];
a[x]=a[x+1];
a[x+1]=t;
}
}
end
end
end
end
댓글 수: 1
madhan ravi
2018년 12월 9일
please don’t close question that have an answer
답변 (1개)
madhan ravi
2018년 12월 8일
Disclaimer : Just an approximate code
x=1;
phase=0;
while phase<n
if phase==0
while x<n
if a(x-1)>a(x)
t=a(x);
a(x)=a(x-1);
a(x-1)=t;
end
x=x+2;
end
end
phase=phase+1;
end
카테고리
도움말 센터 및 File Exchange에서 Simulink 3D Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!