Advertisement
Guest User

Lista dodaj

a guest
Jan 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. struct lista {
  5. int i;
  6. struct lista *next;
  7. };
  8. void Dodaj(struct lista *,int,int);
  9. void print_lista(struct lista *);
  10.  
  11. void main(){
  12. struct lista *p,*q,*t;
  13. int n;
  14. p=(struct lista *)malloc(sizeof(struct lista));
  15. p->next=NULL;
  16. scanf("%d",&n);
  17. p->i=n;
  18. t=p;
  19. while(n<30){
  20.     q=(struct lista *)malloc(sizeof(struct lista));
  21.     scanf("%d",&n);
  22.     q->next=NULL;
  23.     q->i=n;
  24.     t->next=q;
  25.     t=q;
  26.     }
  27.     print_lista(p);
  28.  
  29.     Dodaj(p,3,4);
  30.     printf("Nova listaj je:\n");
  31.     print_lista(p);
  32.  
  33. }
  34.  
  35. void print_lista(struct lista *p){
  36. struct lista *q=p;
  37. while(q!=NULL){
  38.     printf("%d ",q->i);
  39.     q=q->next;
  40.     }
  41.  
  42. }
  43. void Dodaj(struct lista *gl,int m,int n){
  44. struct lista *p,*kraj,*Nrep;
  45. int i,br=0;
  46. p=gl;
  47. while(p!=NULL){
  48.     br++;
  49.     p=p->next;
  50. }
  51. if(m>0){
  52.         p=gl;
  53.     while(p->next!=NULL){
  54.         p=p->next;
  55.     }
  56.     kraj=p;
  57.     i=br;
  58.     while(i+1<br+n){
  59.            Nrep=(struct lista *)malloc(sizeof(struct lista));
  60.            Nrep->i=n;
  61.             Nrep->next=NULL;
  62.             kraj->next=Nrep;
  63.             kraj=Nrep;
  64.              i++;
  65.              p=p->next;
  66.           }
  67.  
  68.  
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement