How to write this pseudocode in matlab?
Afficher commentaires plus anciens
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 commentaire
madhan ravi
le 9 Déc 2018
please don’t close question that have an answer
Réponses (1)
madhan ravi
le 8 Déc 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
Catégories
En savoir plus sur Simulink 3D Animation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!