Advertisement
Denny707

base linked list c

Jun 15th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX 50
  3. typedef struct nodo{
  4. char cognome[MAX];
  5. char nome[MAX];
  6. int eta;
  7. int prezzo;
  8. struct nodo* link;
  9. };
  10.  
  11. void add(struct nodo * head, int n){
  12. struct nodo* nuovo =(struct nodo*)malloc(sizeof(struct nodo));
  13. nuovo->eta=n;
  14. nuovo->link=NULL;
  15. if(head->link==NULL){
  16. head->link=nuovo;
  17. }else{
  18. add(head->link,n);
  19. }
  20. }
  21.  
  22. void display(struct nodo * head){
  23. if(head){
  24. printf("%d\n",head->eta);
  25. display(head->link);
  26. }
  27. }
  28.  
  29. int main(int argc, const char * argv[]) {
  30. struct nodo* head =(struct nodo*)malloc(sizeof(struct nodo));
  31. head->eta=2;
  32. add(head,4);
  33. add(head,4);
  34. add(head,4);
  35. add(head,4);
  36. add(head,4);
  37. display(head);
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement