Advertisement
100rads

red

Nov 20th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. typedef struct _cvor* Position;
  6. typedef struct _cvor
  7. {
  8.     int broj;
  9.     Position next;
  10.     Position last;
  11. }Cvor;
  12.  
  13. int Push(Position);
  14. int Pop(Position);
  15. int Ispis(Position);
  16. Position GenerirajClan(int);
  17. int DodajNaPocetak(Position, Position);
  18.  
  19. int main()
  20. {
  21.     Cvor niz;
  22.     int unos = 0;
  23.     srand((unsigned)time(NULL));
  24.  
  25.     niz.next = NULL;
  26.  
  27.     while (unos != 4)
  28.     {
  29.         printf("Unesite 1 za push, 2 za pop, 3 za ispis liste, 4 za prekid: ");
  30.         scanf(" %d", &unos);
  31.  
  32.         if (unos == 1)
  33.             Push(&niz);
  34.         else if (unos == 2)
  35.             Pop(&niz);
  36.         else if (unos == 3)
  37.             Ispis(niz.next);
  38.         else if (unos != 4)
  39.             printf("Pogresan unos!\n");
  40.     }
  41.  
  42.     return 0;
  43. }
  44.  
  45. int Push(Position head)
  46. {
  47.     int temp;
  48.     temp = rand() % (100 - 10 + 1) + 10;
  49.     DodajNaPocetak(head, GenerirajClan(temp));
  50.     return 0;
  51. }
  52.  
  53. int Pop(Position head)
  54. {
  55.     while(head->next->next != NULL)
  56.     {
  57.         head = head->next;
  58.     }
  59.     head->next = NULL;
  60.     return 0;
  61. }
  62.  
  63. Position GenerirajClan(int broj)
  64. {
  65.     Position noviCvor;
  66.     noviCvor = (Position)malloc(sizeof(Cvor));
  67.     noviCvor->broj = broj;
  68.     noviCvor->next = NULL;
  69.  
  70.     return noviCvor;
  71. }
  72.  
  73. int DodajNaPocetak(Position head, Position novi)
  74. {
  75.     novi->next = head->next;
  76.     head->next = novi;
  77.  
  78.     return 0;
  79. }
  80.  
  81. Ispis(Position position)
  82. {
  83.     while (position != NULL)
  84.     {
  85.         printf("%d ", position->broj);
  86.         position = position->next;
  87.     }
  88.     printf("\n");
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement