Advertisement
Guest User

GlaavaRep

a guest
Jan 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct lista {
  4. int i;
  5. struct lista *next;
  6. };
  7. struct lista *GlavaRep(struct lista *,int,int);
  8. void print_lista(struct lista *);
  9.  
  10. void main(){
  11. struct lista *p,*q,*t,*l;
  12. int n;
  13. p=(struct lista *)malloc(sizeof(struct lista));
  14. p->next=NULL;
  15. scanf("%d",&n);
  16. p->i=n;
  17. t=p;
  18. while(n<30){
  19.     q=(struct lista *)malloc(sizeof(struct lista));
  20.     scanf("%d",&n);
  21.     q->next=NULL;
  22.     q->i=n;
  23.     t->next=q;
  24.     t=q;
  25.     }
  26.  
  27.     l=GlavaRep(p,2,4);
  28.     printf("\n");
  29.     print_lista(l);
  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. struct lista *GlavaRep(struct lista *gl,int r,int q){
  42. struct lista *p,*Ngl,*Nrep,*d;
  43. int i;
  44. p=gl;
  45. while(p->next!=NULL){
  46.     p=p->next;
  47. }
  48. Nrep=(struct lista *)malloc(sizeof(struct lista));
  49. Nrep->i=q;
  50. p->next=Nrep;
  51. Nrep->next=NULL;
  52. p=gl;
  53. Ngl=(struct lista *)malloc(sizeof(struct lista));
  54. Ngl->i=r;
  55. Ngl->next=p;
  56.  
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement