How to write this pseudocode in matlab?
Show older comments
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 Comment
madhan ravi
on 9 Dec 2018
please don’t close question that have an answer
Answers (1)
madhan ravi
on 8 Dec 2018
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
Categories
Find more on Simulink 3D Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!