Advertisement
Guest User

Lista izmjena

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