Advertisement
Guest User

MakniN

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