#include <stdio.h>
#include <stdlib.h>
struct cel
{
int valor;
struct cel * prox;
};
typedef struct cel celula;
int inserir(celula **ini);
void escreve(celula *ini);
int main()
{
int i = 0,aux;
celula *inicio = NULL;
do
{
aux = inserir(&inicio);
i++;
} while (aux == 1);
escreve(inicio);
return 0;
}
int inserir(celula **ini)
{
int n;
if(n == 0)
return 0;
celula
* aux
= (celula
*) malloc(sizeof(celula
));
aux->valor = n;
aux->prox = ini == NULL ? NULL : *ini;
*ini = aux;
return 1;
}
void escreve(celula *ini)
{
int i=1;
celula * aux =ini;
while(aux != NULL)
{
printf("\nlista[%d]=%d",i
,aux
->valor
); i++;
aux = aux->prox;
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnN0cnVjdCBjZWwKewogICAgaW50IHZhbG9yOwogICAgc3RydWN0IGNlbCAqIHByb3g7Cn07Cgp0eXBlZGVmIHN0cnVjdCBjZWwgY2VsdWxhOwoKaW50IGluc2VyaXIoY2VsdWxhICoqaW5pKTsKdm9pZCBlc2NyZXZlKGNlbHVsYSAqaW5pKTsKCmludCBtYWluKCkKewogICAgaW50IGkgPSAwLGF1eDsKICAgIGNlbHVsYSAqaW5pY2lvID0gTlVMTDsKCiAgICBkbwogICAgewogICAgICAgIHByaW50ZigiXG5MaXN0YVslZF06IixpKzEpOwogICAgICAgIGF1eCA9IGluc2VyaXIoJmluaWNpbyk7CiAgICAgICAgcHJpbnRmKCJcbiVkIixhdXgpOwogICAgICAgIGkrKzsKICAgIH0gd2hpbGUgKGF1eCA9PSAxKTsKICAgIGVzY3JldmUoaW5pY2lvKTsKICAgIAogICAgcmV0dXJuIDA7Cn0KCmludCBpbnNlcmlyKGNlbHVsYSAqKmluaSkKewogICAgaW50IG47CiAgICBzY2FuZigiJWQiLCZuKTsKICAgIGlmKG4gPT0gMCkKICAgICAgICByZXR1cm4gMDsKCiAgICBjZWx1bGEgKiBhdXggPSAoY2VsdWxhKikgbWFsbG9jKHNpemVvZihjZWx1bGEpKTsKCiAgICBhdXgtPnZhbG9yID0gbjsKICAgIGF1eC0+cHJveCA9IGluaSA9PSBOVUxMID8gTlVMTCA6ICppbmk7CiAgICAqaW5pID0gYXV4OwoKICAgIHJldHVybiAxOwp9Cgp2b2lkIGVzY3JldmUoY2VsdWxhICppbmkpCnsKICAgIGludCBpPTE7CiAgICBjZWx1bGEgKiBhdXggPWluaTsKCiAgICB3aGlsZShhdXggIT0gTlVMTCkKICAgIHsKICAgICAgICBwcmludGYoIlxubGlzdGFbJWRdPSVkIixpLGF1eC0+dmFsb3IpOwogICAgICAgIGkrKzsKICAgICAgICBhdXggPSBhdXgtPnByb3g7CiAgICB9Cn0K