Advertisement
Guest User

DodajNcvor 2013-2014

a guest
Jan 20th, 2018
76
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. struct lista {
  3. int i;
  4. struct lista *next;
  5. };
  6. void dodajn(struct lista *,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.    dodajn(p,3);
  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 dodajn(struct lista *gl,int n){
  42. struct lista *p,*Nrep;
  43. int i,br=0,pom;
  44. p=gl;
  45. while(p!=NULL){
  46.     br++;
  47.     p=p->next;
  48. }
  49. if(n>0 && n<br){
  50.     i=1;
  51.     p=gl;
  52.     while(p!=NULL)
  53. {
  54.     if(i==n){
  55.         break;
  56.     }
  57.     i++;
  58.     p=p->next;
  59. }
  60. pom=p->i;
  61. while(p->next!=NULL){
  62.     p=p->next;
  63. }
  64. Nrep=(struct lista *)malloc(sizeof(struct lista));
  65. Nrep->i=pom;
  66. p->next=Nrep;
  67. Nrep->next=NULL;
  68.  
  69. }
  70. else{
  71.     printf("van opsega");
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement