Guest User

Untitled

a guest
Jan 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #define MEMCHECK(x) if(x==NULL) { printf("Nema memorija!\n"); exit(-1); }
  4.  
  5.  
  6. typedef int info_t;
  7.  
  8. typedef struct element
  9. {
  10. info_t info;
  11. struct element *link;
  12. } node;
  13. typedef node * nodep;
  14.  
  15. main()
  16. {
  17. nodep p;
  18. node *mk_link_list(int);
  19. int n;
  20.  
  21. printf("Kolku nodea: ");
  22. scanf("%d",&n);
  23. p=mk_link_list(n);
  24.  
  25. sumiraj(p);
  26. }
  27.  
  28. node *mk_link_list(int n)
  29. {
  30. node *p=NULL,*q=NULL;
  31. void fillel(node *);
  32.  
  33. while(n--)
  34. {
  35. p=(node *)malloc(sizeof(node));
  36. MEMCHECK(p);
  37. p->link=q;
  38. q=p;
  39. }
  40. while(q!=NULL)
  41. {
  42. fillel(q);
  43. q=q->link;
  44. }
  45. return(p);
  46. }
  47.  
  48. void fillel(node *q)
  49. {
  50. scanf("%d",&q->info);
  51. }
  52.  
  53. int sumiraj(nodep l)
  54. {
  55. int sum = 0;
  56. nodep t = l -> link;
  57. while ( t != NULL)
  58. sum += t->info;
  59. t = t -> link;
  60. return sum;
  61. }
Add Comment
Please, Sign In to add comment