Advertisement
Guest User

prebaci

a guest
Jan 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. struct lista {
  5. int i;
  6. struct lista *next;
  7. };
  8. void Pre(struct lista *,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.     Pre(p,3);
  30.     printf("Nova lista je");
  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 Pre(struct lista *gl,int n){
  44. struct lista *p,*a,*b,*c,*d;
  45. int i,pom,pom1;
  46. p=gl;
  47. i=1;
  48. while(p!=NULL){
  49.     if(i==n-1){
  50.             a=p;
  51.     p=p->next;
  52.     b=p;
  53.     p=p->next;
  54.     c=p;
  55.         break;
  56.     }
  57.     else{
  58.     i++;
  59.     p=p->next;
  60. }
  61. }
  62. pom=b->i;
  63. p=gl;
  64. while(p->next!=NULL){
  65.     p=p->next;
  66. }
  67. d=p;
  68. d->i=pom;
  69. a->next=c;
  70. b->next=NULL;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement