Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #define MEMCHECK(x) if(x==NULL) { printf("Nema memorija!\n"); exit(-1); }
- typedef int info_t;
- typedef struct element
- {
- info_t info;
- struct element *link;
- } node;
- typedef node * nodep;
- main()
- {
- nodep p;
- node *mk_link_list(int);
- int n;
- printf("Kolku nodea: ");
- scanf("%d",&n);
- p=mk_link_list(n);
- sumiraj(p);
- }
- node *mk_link_list(int n)
- {
- node *p=NULL,*q=NULL;
- void fillel(node *);
- while(n--)
- {
- p=(node *)malloc(sizeof(node));
- MEMCHECK(p);
- p->link=q;
- q=p;
- }
- while(q!=NULL)
- {
- fillel(q);
- q=q->link;
- }
- return(p);
- }
- void fillel(node *q)
- {
- scanf("%d",&q->info);
- }
- int sumiraj(nodep l)
- {
- int sum = 0;
- nodep t = l -> link;
- while ( t != NULL)
- sum += t->info;
- t = t -> link;
- return sum;
- }
Add Comment
Please, Sign In to add comment