fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define VALUE(p) ((p) -> value)
  5. #define NXT(p) ((p) -> nxt)
  6.  
  7. typedef struct node {
  8. int value;
  9. struct node *nxt;
  10. } NODE;
  11.  
  12. NODE * new_node (int v, NODE *prox) {
  13. NODE *l= (NODE*)malloc(sizeof(NODE));
  14.  
  15. VALUE(l)= v;
  16. NXT(l) = prox;
  17.  
  18. return l;
  19. }
  20.  
  21. NODE *add_last(int x, NODE *l) {
  22.  
  23. NODE *curr=l;
  24.  
  25. if(l==NULL) {
  26. NODE *aux = new_node(x, l);
  27. l=aux;
  28. return l;
  29. }
  30.  
  31.  
  32. while(NXT(curr)!=NULL) {
  33. curr=NXT(curr);
  34. }
  35.  
  36. NXT(curr)= new_node (x, NULL);
  37. return l;
  38. }
  39.  
  40. int main() {
  41. NODE *lista=NULL;
  42. lista = add_last(6, lista);
  43.  
  44. printf("%d", lista->value);
  45. }
  46.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
6