#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 j;
int k;
// Inizia il ciclo di scansione dell'array.
for (j = a; j < z; j++)
{
// Scansione interna dell'array per collocare nella
// posizione j l'elemento giusto.
for (k = j+1; k <= z; k++)
{
if (lista[k] < lista[j])
{
// Scambia i valori.
scambio = lista[k];
lista[k] = lista[j];
lista[j] = scambio;
}
}
}
}
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+CgpjaGFyICppbnB1dF9hcmd2W10gPSB7ICJwcm9nLmMiLCAiMTIiLCAiMTAiLCAiMTciLCAiMSIsICIyMiIgfTsgICAgIC8vIGFsIHBvc3RvIGRpIGFyZ3ZbXQppbnQgICBpbnB1dF9hcmdjICAgPSBzaXplb2YgKGlucHV0X2FyZ3YpIC8gc2l6ZW9mIChpbnB1dF9hcmd2WzBdKTsgIC8vIGFsIHBvc3RvIGRpIGFyZ2MKCnZvaWQKYnNvcnQgKGludCBsaXN0YVtdLCBpbnQgYSwgaW50IHopCnsKICAgIGludCBzY2FtYmlvOwogICAgaW50IGo7CiAgICBpbnQgazsKCiAgICAvLyBJbml6aWEgaWwgY2ljbG8gZGkgc2NhbnNpb25lIGRlbGwnYXJyYXkuCgogICAgZm9yIChqID0gYTsgaiA8IHo7IGorKykKICAgICAgewogICAgICAgIC8vIFNjYW5zaW9uZSBpbnRlcm5hIGRlbGwnYXJyYXkgcGVyIGNvbGxvY2FyZSBuZWxsYQogICAgICAgIC8vIHBvc2l6aW9uZSBqIGwnZWxlbWVudG8gZ2l1c3RvLgoKICAgICAgICBmb3IgKGsgPSBqKzE7IGsgPD0gejsgaysrKQogICAgICAgICAgewogICAgICAgICAgICBpZiAobGlzdGFba10gPCBsaXN0YVtqXSkKICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAvLyBTY2FtYmlhIGkgdmFsb3JpLgoKICAgICAgICAgICAgICAgIHNjYW1iaW8gPSBsaXN0YVtrXTsKICAgICAgICAgICAgICAgIGxpc3RhW2tdID0gbGlzdGFbal07CiAgICAgICAgICAgICAgICBsaXN0YVtqXSA9IHNjYW1iaW87CiAgICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICB9Cn0KCmludAptYWluIChpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CiAgICBpbnQgbGlzdGFbaW5wdXRfYXJnYy0xXTsKICAgIGludCBpOwoKICAgIC8vIENvbnNpZGVyYSBnbGkgYXJnb21lbnRpIGNvbWUgZ2xpIGVsZW1lbnRpCiAgICAvLyBkZWxsJ2FycmF5IGRhIG9yZGluYXJlLgoKICAgIGZvciAoaSA9IDE7IGkgPCBpbnB1dF9hcmdjOyBpKyspCiAgICAgIHsKICAgICAgICBzc2NhbmYgKGlucHV0X2FyZ3ZbaV0sICIlaSIsICZsaXN0YVtpLTFdKTsKICAgICAgfQoKICAgIC8vIEVzZWd1ZSBpbCByaW9yZGluby4KCiAgICBic29ydCAobGlzdGEsIDAsIGlucHV0X2FyZ2MtMik7CgogICAgLy8gRW1ldHRlIGlsIHJpc3VsdGF0by4KCiAgICBmb3IgKGkgPSAwOyBpIDwgKGlucHV0X2FyZ2MtMSk7IGkrKykKICAgICAgewogICAgICAgIHByaW50ZiAoIiVpICIsIGxpc3RhW2ldKTsKICAgICAgfQogICAgcHJpbnRmICgiXG4iKTsKCiAgICByZXR1cm4gMDsKfQ==