fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4.  
  5. struct tipo_lista{
  6. int info;
  7. struct tipo_lista * prox;
  8. };
  9.  
  10. typedef struct tipo_lista tipo_lista;
  11.  
  12. tipo_lista * cria_no (int valor)
  13. {
  14. tipo_lista * novo;
  15. novo = (tipo_lista *)malloc(sizeof(tipo_lista));
  16. novo -> info = valor;
  17. novo -> prox = NULL;
  18. return novo;
  19. }
  20.  
  21. bool inserir_fim (tipo_lista * p, tipo_lista * novo_no)
  22. {
  23. if (!p) {
  24. return false;
  25. }
  26.  
  27. while (p->prox) {
  28. p = p->prox;
  29. }
  30.  
  31. p->prox = novo_no;
  32.  
  33. return true;
  34. }
  35.  
  36. int main(void) {
  37. tipo_lista * p = cria_no(1);
  38. inserir_fim(p, cria_no(2));
  39. printf("%d %d\n", p->info, p->prox->info);
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
1 2