Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #define X 100000
- #define Y 100000
- // REKURZIJA
- // ---------------------------------------
- int povrh(int n, int m)
- {
- if (n == m || n == 1 || m == 0)
- return 1;
- return povrh(n - 1, m - 1) + povrh(n - 1, m);
- }
- // ---------------------------------------
- // NIZ
- // ---------------------------------------
- /* int stog1[X];
- int sp1 = -1;
- int stog2[Y];
- int sp2 = -1;
- void push1(int x)
- {
- if (sp1 == (X - 1))
- printf("Stog je pun.\n");
- else
- stog1[++sp1] = x;
- }
- int pop1()
- {
- if (sp1 == -1)
- printf("Stog je prazan.\n");
- else
- return stog1[sp1--];
- }
- void clear1()
- {
- sp1 = -1;
- }
- bool isempty1()
- {
- if (sp1 == -1)
- return true;
- return false;
- }
- void push2(int x)
- {
- if (sp2 == (Y - 1))
- printf("Stog je pun.\n");
- else
- stog2[++sp2] = x;
- }
- int pop2()
- {
- if (sp2 == -1)
- printf("Stog je prazan.\n");
- else
- return stog2[sp2--];
- }
- void clear2()
- {
- sp2 = -1;
- }
- bool isempty2()
- {
- if (sp2 == -1)
- return true;
- return false;
- } */
- // ---------------------------------------
- // POVEZANI POPIS
- // ---------------------------------------
- /* typedef struct podatak
- {
- int x;
- struct podatak *sljedeci;
- };
- podatak *prvi = NULL;
- podatak *drugi = NULL;
- void push1(int a)
- {
- podatak *novi;
- novi = new podatak;
- if (novi == NULL)
- {
- printf("Stog je pun.\n");
- }
- else
- {
- novi->x = a;
- novi->sljedeci = prvi;
- prvi = novi;
- }
- }
- int pop1()
- {
- if (prvi == NULL)
- {
- printf("Stog je prazan.\n");
- }
- else
- {
- int x;
- podatak *zabrisanje = prvi;
- prvi = prvi->sljedeci;
- x = zabrisanje->x;
- delete zabrisanje;
- return x;
- }
- }
- void clear1()
- {
- prvi = NULL;
- }
- bool isempty1()
- {
- if (prvi == NULL)
- return true;
- return false;
- }
- void push2(int a)
- {
- podatak *novi;
- novi = new podatak;
- if (novi == NULL)
- {
- printf("Stog je pun.\n");
- }
- else
- {
- novi->x = a;
- novi->sljedeci = drugi;
- drugi = novi;
- }
- }
- int pop2()
- {
- if (drugi == NULL)
- {
- printf("Stog je prazan.\n");
- }
- else
- {
- int x;
- podatak *zabrisanje = drugi;
- drugi = drugi->sljedeci;
- x = zabrisanje->x;
- delete zabrisanje;
- return x;
- }
- }
- void clear2()
- {
- drugi = NULL;
- }
- bool isempty2()
- {
- if (drugi == NULL)
- return true;
- return false;
- } */
- // ---------------------------------------
- // STOG
- // ---------------------------------------
- /* int povrh(int a, int b)
- {
- clear1();
- clear2();
- push1(a);
- push2(b);
- int povrh = 0;
- while (isempty1() != true)
- {
- int n = pop1();
- int m = pop2();
- if ((n == m) || (n == 1) || (m == 0))
- povrh++;
- else
- {
- push1(n - 1);
- push2(m - 1);
- push1(n - 1);
- push2(m);
- }
- }
- return povrh;
- } */
- // ---------------------------------------
- int main(void)
- {
- time_t t1, t2;
- int n = 20;
- int m = n / 2;
- t1 = clock();
- printf("%d povrh %d: %d\n", n, m, povrh(n, m));
- t2 = clock();
- printf("Vrijeme trajanja je %dms\n", t2 - t1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement