//http://pt.stackoverflow.com/questions/158694/duvida-em-um-programa-em-c-lista-simplesmente-encadeada
#include <stdio.h>
#include <stdlib.h>
typedef struct celula_s{
int valor;
struct nodo *prox;
} lista_t;
lista_t* lista_inicializar(void);
lista_t* lista_inserir_inicio(lista_t* lista, int valor);
int lista_imprimir(lista_t* lista);
int main (int argc, char *argv[]){
lista_t* lista = lista_inicializar();
lista = lista_inserir_inicio(lista, 10);
lista = lista_inserir_inicio(lista, 20);
lista = lista_inserir_inicio(lista, 30);
lista_imprimir(lista);
}
lista_t* lista_inicializar(void){
lista_t
* lista
= (lista_t
*) malloc( sizeof (lista_t
) ); //lista->valor = 0;
//lista->prox = NULL;
return lista;
}
lista_t* lista_inserir_inicio(lista_t* lista, int valor){
lista_t* novo = lista_inicializar();
if(novo != NULL){
novo->valor = valor;
novo->prox = lista;
lista = novo;
}
return lista;
}
int lista_imprimir(lista_t* lista){
lista_t* aux;
aux = lista;
while (aux->prox != NULL){
aux = aux->prox;
}
return 0;
}
Ly9odHRwOi8vcHQuc3RhY2tvdmVyZmxvdy5jb20vcXVlc3Rpb25zLzE1ODY5NC9kdXZpZGEtZW0tdW0tcHJvZ3JhbWEtZW0tYy1saXN0YS1zaW1wbGVzbWVudGUtZW5jYWRlYWRhCgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKdHlwZWRlZiBzdHJ1Y3QgY2VsdWxhX3N7CgogICAgaW50ICAgICB2YWxvcjsKICAgIHN0cnVjdCAgbm9kbyAqcHJveDsKCn0gbGlzdGFfdDsKCmxpc3RhX3QqIGxpc3RhX2luaWNpYWxpemFyKHZvaWQpOwpsaXN0YV90KiBsaXN0YV9pbnNlcmlyX2luaWNpbyhsaXN0YV90KiBsaXN0YSwgaW50IHZhbG9yKTsKaW50IGxpc3RhX2ltcHJpbWlyKGxpc3RhX3QqIGxpc3RhKTsKCmludCBtYWluIChpbnQgYXJnYywgY2hhciAqYXJndltdKXsKICAgIGxpc3R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