Advertisement
amarek

AISP - LV3

Nov 11th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. #define X 100000
  6. #define Y 100000
  7.  
  8. // REKURZIJA
  9.  
  10. // ---------------------------------------
  11.  
  12. int povrh(int n, int m)
  13. {
  14.     if (n == m || n == 1 || m == 0)
  15.         return 1;
  16.     return povrh(n - 1, m - 1) + povrh(n - 1, m);
  17. }
  18.  
  19. // ---------------------------------------
  20.  
  21. //  NIZ
  22.  
  23. // ---------------------------------------
  24.  
  25. /* int stog1[X];
  26. int sp1 = -1;
  27.  
  28. int stog2[Y];
  29. int sp2 = -1;
  30.  
  31. void push1(int x)
  32. {
  33.     if (sp1 == (X - 1))
  34.         printf("Stog je pun.\n");
  35.     else
  36.         stog1[++sp1] = x;
  37. }
  38.  
  39. int pop1()
  40. {
  41.     if (sp1 == -1)
  42.         printf("Stog je prazan.\n");
  43.     else
  44.         return stog1[sp1--];
  45. }
  46.  
  47. void clear1()
  48. {
  49.     sp1 = -1;
  50. }
  51.  
  52. bool isempty1()
  53. {
  54.     if (sp1 == -1)
  55.         return true;
  56.     return false;
  57. }
  58.  
  59. void push2(int x)
  60. {
  61.     if (sp2 == (Y - 1))
  62.         printf("Stog je pun.\n");
  63.     else
  64.         stog2[++sp2] = x;
  65. }
  66.  
  67. int pop2()
  68. {
  69.     if (sp2 == -1)
  70.         printf("Stog je prazan.\n");
  71.     else
  72.         return stog2[sp2--];
  73. }
  74.  
  75. void clear2()
  76. {
  77.     sp2 = -1;
  78. }
  79.  
  80. bool isempty2()
  81. {
  82.     if (sp2 == -1)
  83.         return true;
  84.     return false;
  85. } */
  86.  
  87. // ---------------------------------------
  88.  
  89. //  POVEZANI POPIS
  90.  
  91. // ---------------------------------------
  92.  
  93. /* typedef struct podatak
  94. {
  95.     int x;
  96.     struct podatak *sljedeci;
  97. };
  98.  
  99. podatak *prvi = NULL;
  100. podatak *drugi = NULL;
  101.  
  102. void push1(int a)
  103. {
  104.     podatak *novi;
  105.     novi = new podatak;
  106.  
  107.     if (novi == NULL)
  108.     {
  109.         printf("Stog je pun.\n");
  110.     }
  111.     else
  112.     {
  113.         novi->x = a;
  114.         novi->sljedeci = prvi;
  115.         prvi = novi;
  116.     }
  117. }
  118.  
  119. int pop1()
  120. {
  121.     if (prvi == NULL)
  122.     {
  123.         printf("Stog je prazan.\n");
  124.     }
  125.     else
  126.     {
  127.         int x;
  128.  
  129.         podatak *zabrisanje = prvi;
  130.         prvi = prvi->sljedeci;
  131.         x = zabrisanje->x;
  132.         delete zabrisanje;
  133.  
  134.         return x;
  135.     }
  136. }
  137.  
  138. void clear1()
  139. {
  140.     prvi = NULL;
  141. }
  142.  
  143. bool isempty1()
  144. {
  145.     if (prvi == NULL)
  146.         return true;
  147.     return false;
  148. }
  149.  
  150. void push2(int a)
  151. {
  152.     podatak *novi;
  153.     novi = new podatak;
  154.  
  155.     if (novi == NULL)
  156.     {
  157.         printf("Stog je pun.\n");
  158.     }
  159.     else
  160.     {
  161.         novi->x = a;
  162.         novi->sljedeci = drugi;
  163.         drugi = novi;
  164.     }
  165. }
  166.  
  167. int pop2()
  168. {
  169.     if (drugi == NULL)
  170.     {
  171.         printf("Stog je prazan.\n");
  172.     }
  173.     else
  174.     {
  175.         int x;
  176.  
  177.         podatak *zabrisanje = drugi;
  178.         drugi = drugi->sljedeci;
  179.         x = zabrisanje->x;
  180.         delete zabrisanje;
  181.  
  182.         return x;
  183.     }
  184. }
  185.  
  186. void clear2()
  187. {
  188.     drugi = NULL;
  189. }
  190.  
  191. bool isempty2()
  192. {
  193.     if (drugi == NULL)
  194.         return true;
  195.     return false;
  196. } */
  197.  
  198. // ---------------------------------------
  199.  
  200. //  STOG
  201.  
  202. // ---------------------------------------
  203.  
  204. /* int povrh(int a, int b)
  205. {
  206.     clear1();
  207.     clear2();
  208.  
  209.     push1(a);
  210.     push2(b);
  211.  
  212.     int povrh = 0;
  213.  
  214.     while (isempty1() != true)
  215.     {
  216.         int n = pop1();
  217.         int m = pop2();
  218.  
  219.         if ((n == m) || (n == 1) || (m == 0))
  220.             povrh++;
  221.         else
  222.         {
  223.             push1(n - 1);
  224.             push2(m - 1);
  225.             push1(n - 1);
  226.             push2(m);
  227.         }
  228.     }
  229.  
  230.     return povrh;
  231. } */
  232.  
  233. // ---------------------------------------
  234.  
  235. int main(void)
  236. {
  237.     time_t t1, t2;
  238.     int n = 20;
  239.     int m = n / 2;
  240.  
  241.     t1 = clock();
  242.     printf("%d povrh %d: %d\n", n, m, povrh(n, m));
  243.     t2 = clock();
  244.  
  245.     printf("Vrijeme trajanja je %dms\n", t2 - t1);
  246.     return 0;
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement