Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. typedef struct list_element{
  6. int value;
  7. struct list_element *next;
  8. }item;
  9. typedef item *list;
  10.  
  11. list inserimento(int n, list root) {
  12. list prec;
  13. list agg;
  14. list patt = root;
  15.  
  16. agg = (list)malloc(sizeof(item));
  17. agg->value = n;
  18. agg->next = NULL;
  19. if (root == NULL) {
  20. return agg;
  21. }
  22. else {
  23. while (patt != NULL) {
  24. prec = patt;
  25. patt = patt->next;
  26. }
  27. prec->next= agg;
  28. return root;
  29. }
  30. }
  31.  
  32. void stampa(list root) {
  33. list t = root;
  34. while (t != NULL) {
  35. printf("%d \n", t->value);
  36. t = t->next;
  37. }
  38. }
  39. main() {
  40. list root;
  41. int indice = 1;
  42. int n = 0;
  43. int flag = 0;
  44. root = NULL;
  45. do {
  46. printf("inserire il %d elemento \n", indice);
  47. scanf("%d", &n);
  48. root = inserimento(n, root);
  49. indice++;
  50. } while (n != 0);
  51. stampa(root);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement