Advertisement
100rads

stog

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