Advertisement
Crackbone

SP-Vjezba6-wip

Nov 15th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1.  
  2. /*6. Napisati program koji pomoću vezanih listi simulira rad:
  3. a) stoga,
  4. b) reda.
  5. Napomena: Funkcija "push" sprema cijeli broj, slučajno generirani u opsegu od 10 -100*/
  6.  
  7. #define _CRT_SECURE_NO_WARNINGS
  8. #define Lower 10
  9. #define Upper 100
  10. #include<stdio.h>
  11. #include<stdlib.h>
  12. #include<time.h>
  13.  
  14.  
  15. //Struktura
  16. struct node;
  17. typedef struct node* Pnode;
  18. struct node
  19. {
  20.     int broj;
  21.     Pnode Next;
  22. };
  23. //random
  24. int random()
  25. {
  26.     int x = 0;
  27.     srand((unsigned)time(0));
  28.     x = (rand() % (Upper - Lower)) + Lower;
  29.  
  30.     return x;
  31. }
  32.  
  33. //ClearScren
  34. /*void clrscr()
  35. {
  36.     system("@cls||clear");
  37. }*/
  38. //Funkcije
  39. int push(Pnode);
  40. void meni();
  41. void print(Pnode);
  42.  
  43. int main()
  44. {
  45.     struct node Stack, Queue;
  46.     Stack.Next= NULL;
  47.     Queue.Next = NULL;
  48.     int izbor = 0;
  49.     do {
  50.        
  51.         meni();
  52.         scanf(" %d", &izbor);
  53.         switch (izbor)
  54.         {
  55.         case 1:
  56.             push(&Stack);
  57.         case 2:
  58.             push(&Queue);
  59.  
  60.         case 5:
  61.             print(Stack.Next);
  62.         //case 7:
  63.             //clrscr();
  64.  
  65.  
  66.  
  67.         }
  68.     } while (izbor != 8);
  69.  
  70.     getchar();
  71.     getchar();
  72.     return 0;
  73. }
  74.  
  75. int push(Pnode P)
  76. {
  77.     Pnode q;
  78.     q = (Pnode)malloc(sizeof(struct node));
  79.     if (NULL == q)
  80.     {
  81.         printf("Greska kod alokacije memorije\n");
  82.         return -1;
  83.     }
  84.     else
  85.     {
  86.         //Zavrsi ovo
  87.         q->broj = random();
  88.         q->Next = P->Next;
  89.         P->Next = q;
  90.     }
  91.  
  92.     return 1;
  93. }
  94.  
  95. void meni()
  96. {
  97.    
  98.     printf("\nIzaberi sta oces:\n");
  99.     printf("\nPush to stack:       1");
  100.     printf("\nPush to queue:       2");
  101.     printf("\n:Pop from stack:     3");
  102.     printf("\nPop from queue:      4");
  103.     printf("\nPrint Stack:         5");
  104.     printf("\nPrint Queue:         6");
  105.     printf("\nClearScreen          7");
  106.     printf("\nExit:                8\n");
  107.     printf("_________________________\n");
  108.  
  109.     return;
  110. }
  111.  
  112. void print(Pnode P)
  113. {
  114.     printf("\nIspis:\n ");
  115.     while (P != NULL)
  116.     {
  117.         printf(" %d", P->broj);
  118.         P = P->Next;
  119.     }
  120.     return;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement