Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. struct Broj
  6. {
  7.     int unos;
  8.     struct Broj *next;
  9. };
  10.  
  11. int UmetniIza(struct Broj *head, struct Broj *pocetak);
  12.  
  13. int main()
  14. {
  15.     struct Broj head;
  16.     struct Broj pocetak;
  17.  
  18.     head.next = NULL;
  19.  
  20.     UmetniIza(&head, &pocetak);
  21.     UmetniIza(&head, &pocetak);
  22.     UmetniIza(&head, &pocetak);
  23.  
  24.  
  25.     return 0;
  26. }
  27.  
  28. int UmetniIza(struct Broj *head, struct Broj *pocetak)
  29. {
  30.  
  31.     struct Broj *q = (struct Broj*)malloc(sizeof(struct Broj));
  32.     static int brojac = 0;
  33.  
  34.     pocetak = head;
  35.     printf("Upisi broj\n");
  36.     scanf("%d", &q->unos);
  37.  
  38.  
  39.     if (head->next == NULL)
  40.     {
  41.         q->next = q;
  42.         head->next = q;
  43.         brojac += 1;
  44.     }
  45.     else
  46.     {
  47.         for (int i = 0; i < brojac; i++)
  48.         {
  49.             head = head->next;
  50.         }
  51.  
  52.         head->next = q;
  53.         q->next = pocetak->next;
  54.         brojac += 1;
  55.     }
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement