#include <stdio.h>
#include <stdlib.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
= (int *) malloc ((input_argc
- 1) * sizeof (int)); 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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmNoYXIgKmlucHV0X2FyZ3ZbXSA9IHsgInByb2cuYyIsICIxMiIsICIxMCIsICIxNyIsICIxIiwgIjIyIiB9OyAgICAgLy8gYWwgcG9zdG8gZGkgYXJndltdCmludCAgIGlucHV0X2FyZ2MgICA9IHNpemVvZiAoaW5wdXRfYXJndikgLyBzaXplb2YgKGlucHV0X2FyZ3ZbMF0pOyAgLy8gYWwgcG9zdG8gZGkgYXJnYwoKdm9pZApic29ydCAoaW50IGxpc3RhW10sIGludCBhLCBpbnQgeikKewogICAgaW50IHNjYW1iaW87CiAgICBpbnQgazsKCiAgICBpZiAoYSA8IHopCiAgICAgIHsKICAgICAgICAvLyBTY2Fuc2lvbmUgaW50ZXJuYSBkZWxsJ2FycmF5IHBlciBjb2xsb2NhcmUgbmVsbGEKICAgICAgICAvLyBwb3NpemlvbmUgYSBsJ2VsZW1lbnRvIGdpdXN0by4KCiAgICAgICAgZm9yIChrID0gYSsxOyBrIDw9IHo7IGsrKykKICAgICAgICAgIHsKICAgICAgICAgICAgaWYgKGxpc3RhW2tdIDwgbGlzdGFbYV0pCiAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgLy8gU2NhbWJpYSBpIHZhbG9yaS4KCiAgICAgICAgICAgICAgICBzY2FtYmlvID0gbGlzdGFba107CiAgICAgICAgICAgICAgICBsaXN0YVtrXSA9IGxpc3RhW2FdOwogICAgICAgICAgICAgICAgbGlzdGFbYV0gPSBzY2FtYmlvOwogICAgICAgICAgICAgIH0KICAgICAgICAgIH0KCiAgICAgICAgYnNvcnQgKGxpc3RhLCBhKzEsIHopOwogICAgICB9Cn0KCmludAptYWluIChpbnQgYXJnYywgY2hhciAqYXJndltdKQp7CiAgICBpbnQgKmxpc3RhID0gKGludCAqKSBtYWxsb2MgKChpbnB1dF9hcmdjIC0gMSkgKiBzaXplb2YgKGludCkpOwogICAgaW50IGk7CgogICAgLy8gQ29uc2lkZXJhIGdsaSBhcmdvbWVudGkgY29tZSBnbGkgZWxlbWVudGkKICAgIC8vIGRlbGwnYXJyYXkgZGEgb3JkaW5hcmUuCgogICAgZm9yIChpID0gMTsgaSA8IGlucHV0X2FyZ2M7IGkrKykKICAgICAgewogICAgICAgIHNzY2FuZiAoaW5wdXRfYXJndltpXSwgIiVpIiwgJmxpc3RhW2ktMV0pOwogICAgICB9CgogICAgLy8gRXNlZ3VlIGlsIHJpb3JkaW5vLgoKICAgIGJzb3J0IChsaXN0YSwgMCwgaW5wdXRfYXJnYy0yKTsKCiAgICAvLyBFbWV0dGUgaWwgcmlzdWx0YXRvLgoKICAgIGZvciAoaSA9IDA7IGkgPCAoaW5wdXRfYXJnYy0xKTsgaSsrKQogICAgICB7CiAgICAgICAgcHJpbnRmICgiJWkgIiwgbGlzdGFbaV0pOwogICAgICB9CiAgICBwcmludGYgKCJcbiIpOwoKICAgIHJldHVybiAwOwp9