#include <stdio.h>
char *input_argv[] = { "prog.c", "12", "10", "17", "1", "22" }; // al posto di argv[]
int input_argc = sizeof (input_argv) / sizeof (input_argv[0]); // al posto di argc
void
bsort (int lista[], int a, int z)
{
int scambio;
int k;
if (a < z)
{
// Scansione interna dell'array per collocare nella
// posizione a l'elemento giusto.
for (k = a+1; k <= z; k++)
{
if (lista[k] < lista[a])
{
// Scambia i valori.
scambio = lista[k];
lista[k] = lista[a];
lista[a] = scambio;
}
}
bsort (lista, a+1, z);
}
}
int
main (int argc, char *argv[])
{
int lista[input_argc-1];
int i;
// Considera gli argomenti come gli elementi
// dell'array da ordinare.
for (i = 1; i < input_argc; i++)
{
sscanf (input_argv
[i
], "%i", &lista
[i
-1]); }
// Esegue il riordino.
bsort (lista, 0, input_argc-2);
// Emette il risultato.
for (i = 0; i < (input_argc-1); i++)
{
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpjaGFyICppbnB1dF9hcmd2W10gPSB7ICJwcm9nLmMiLCAiMTIiLCAiMTAiLCAiMTciLCAiMSIsICIyMiIgfTsgICAgIC8vIGFsIHBvc3RvIGRpIGFyZ3ZbXQppbnQgICBpbnB1dF9hcmdjICAgPSBzaXplb2YgKGlucHV0X2FyZ3YpIC8gc2l6ZW9mIChpbnB1dF9hcmd2WzBdKTsgIC8vIGFsIHBvc3RvIGRpIGFyZ2MKCnZvaWQKYnNvcnQgKGludCBsaXN0YVtdLCBpbnQgYSwgaW50IHopCnsKICAgIGludCBzY2FtYmlvOwogICAgaW50IGs7CgogICAgaWYgKGEgPCB6KQogICAgICB7CiAgICAgICAgLy8gU2NhbnNpb25lIGludGVybmEgZGVsbCdhcnJheSBwZXIgY29sbG9jYXJlIG5lbGxhCiAgICAgICAgLy8gcG9zaXppb25lIGEgbCdlbGVtZW50byBnaXVzdG8uCgogICAgICAgIGZvciAoayA9IGErMTsgayA8PSB6OyBrKyspCiAgICAgICAgICB7CiAgICAgICAgICAgIGlmIChsaXN0YVtrXSA8IGxpc3RhW2FdKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIC8vIFNjYW1iaWEgaSB2YWxvcmkuCgogICAgICAgICAgICAgICAgc2NhbWJpbyA9IGxpc3RhW2tdOwogICAgICAgICAgICAgICAgbGlzdGFba10gPSBsaXN0YVthXTsKICAgICAgICAgICAgICAgIGxpc3RhW2FdID0gc2NhbWJpbzsKICAgICAgICAgICAgICB9CiAgICAgICAgICB9CgogICAgICAgIGJzb3J0IChsaXN0YSwgYSsxLCB6KTsKICAgICAgfQp9CgppbnQKbWFpbiAoaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkKewogICAgaW50IGxpc3RhW2lucHV0X2FyZ2MtMV07CiAgICBpbnQgaTsKCiAgICAvLyBDb25zaWRlcmEgZ2xpIGFyZ29tZW50aSBjb21lIGdsaSBlbGVtZW50aQogICAgLy8gZGVsbCdhcnJheSBkYSBvcmRpbmFyZS4KCiAgICBmb3IgKGkgPSAxOyBpIDwgaW5wdXRfYXJnYzsgaSsrKQogICAgICB7CiAgICAgICAgc3NjYW5mIChpbnB1dF9hcmd2W2ldLCAiJWkiLCAmbGlzdGFbaS0xXSk7CiAgICAgIH0KCiAgICAvLyBFc2VndWUgaWwgcmlvcmRpbm8uCgogICAgYnNvcnQgKGxpc3RhLCAwLCBpbnB1dF9hcmdjLTIpOwoKICAgIC8vIEVtZXR0ZSBpbCByaXN1bHRhdG8uCgogICAgZm9yIChpID0gMDsgaSA8IChpbnB1dF9hcmdjLTEpOyBpKyspCiAgICAgIHsKICAgICAgICBwcmludGYgKCIlaSAiLCBsaXN0YVtpXSk7CiAgICAgIH0KICAgIHByaW50ZiAoIlxuIik7CgogICAgcmV0dXJuIDA7Cn0=