#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int num;
struct Node *prox;
} Node;
void imprime(Node *lista) {
Node *tmp = lista;
while (tmp != NULL) {
tmp = tmp->prox;
}
}
void insere(Node **lista, int val) {
Node
*node
= malloc(sizeof(Node
)); node->num = val;
node->prox = NULL;
if (*lista == NULL) {
*lista = node;
} else {
Node *atual = *lista;
while (atual->prox != NULL) {
atual = atual->prox;
}
atual->prox = node;
}
}
int main(void) {
Node *lista = NULL;
insere(&lista, 10);
insere(&lista, 20);
insere(&lista, 5);
imprime(lista);
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnR5cGVkZWYgc3RydWN0IE5vZGUgewogICAgaW50IG51bTsKICAgIHN0cnVjdCBOb2RlICpwcm94Owp9IE5vZGU7Cgp2b2lkIGltcHJpbWUoTm9kZSAqbGlzdGEpIHsKICAgIE5vZGUgKnRtcCA9IGxpc3RhOwogICAgd2hpbGUgKHRtcCAhPSBOVUxMKSB7CiAgICAgICAgcHJpbnRmKCIlZFxuIiwgdG1wLT5udW0pOwogICAgICAgIHRtcCA9IHRtcC0+cHJveDsKICAgIH0KfQoKdm9pZCBpbnNlcmUoTm9kZSAqKmxpc3RhLCBpbnQgdmFsKSB7CiAgICBOb2RlICpub2RlID0gbWFsbG9jKHNpemVvZihOb2RlKSk7CiAgICBub2RlLT5udW0gPSB2YWw7CiAgICBub2RlLT5wcm94ID0gTlVMTDsKICAgIGlmICgqbGlzdGEgPT0gTlVMTCkgewogICAgICAgICpsaXN0YSA9IG5vZGU7CiAgICB9IGVsc2UgewogICAgICAgIE5vZGUgKmF0dWFsID0gKmxpc3RhOwogICAgICAgIHdoaWxlIChhdHVhbC0+cHJveCAhPSBOVUxMKSB7CiAgICAgICAgICAgIGF0dWFsID0gYXR1YWwtPnByb3g7CiAgICAgICAgfQogICAgICAgIGF0dWFsLT5wcm94ID0gbm9kZTsKICAgIH0KfQoKaW50IG1haW4odm9pZCkgewogICAgTm9kZSAqbGlzdGEgPSBOVUxMOwogICAgaW5zZXJlKCZsaXN0YSwgMTApOwogICAgaW5zZXJlKCZsaXN0YSwgMjApOwogICAgaW5zZXJlKCZsaXN0YSwgNSk7CiAgICBpbXByaW1lKGxpc3RhKTsKfQ==