Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <windows.h>
- #include <array>
- #include <iostream>
- using namespace std;
- int DELKA = 20;
- struct args
- {
- int * pole;
- int s;
- int e;
- };
- void vypisPole(int pole[], int size);
- int arrayLen(int p[]);
- int * setridPole(int pole[], int size, int start, int end) {
- int *setrizenePole;
- setrizenePole = new int[DELKA/4];
- int tmp2 = start;
- for (start; start < end - 1; start++) {
- int maxIndex = start;
- for (int j = start + 1; j < ((tmp2) + (size/4)); j++) { //jede do ctvrtiny delky od zacatku pole, pouzivam tmp2, protoze v ni je puvodni hodnota startu, ktery se inkrementuje v hornim foru
- if (pole[j] > pole[maxIndex]) maxIndex = j;
- }
- int tmp = pole[start];
- pole[start] = pole[maxIndex];
- pole[maxIndex] = tmp;
- }
- start = tmp2;
- {
- int i = 0;
- for (start ; start < end; start++)
- {
- setrizenePole[i] = pole[start];
- i++;
- }
- }
- return setrizenePole;
- }
- int * naplnPole(int *p, int size)
- {
- for (int i = 0; i < size ; i++ )
- {
- p[i] = rand() % 20 - 10;
- }
- return p;
- }
- void vypisPole(int pole[], int size){
- for (int i = 0; i < size; i++){
- printf("%d \n", pole[i]);
- }
- printf("\n\n ");
- }
- /*int * SpojPole(int p1[], int p2[])
- {
- int *SpojenePole;
- int velikost = ( sizeof(p1) / sizeof(p1[0]) ) * 2;
- SpojenePole = new int[velikost];
- for(int i=0; i< (velikost); i++)
- {
- if(p1[i] > p2[i])
- {
- SpojenePole[i] = p1[i];
- }
- else
- {
- SpojenePole[i] = p2[i];
- }
- }
- return SpojenePole;
- }*/
- int * SpojPole(int p1[], int p2[])
- {
- int *SpojenePole;
- //int velikost = ( sizeof(p1) / sizeof(p1[0]) );
- int velikost = 5;
- SpojenePole = new int[velikost*2];
- int i = 0;
- int j = 0;
- int d1 = velikost;
- int d2 = velikost;
- while ((i < d1) && (j < d2)) {
- // dosazeni toho mensiho prvku z obou poli a posunuti indexu
- if (p1[i] > p2[j]) {
- SpojenePole[i + j] = p1[i];
- i++;
- }
- else {
- SpojenePole[i + j] = p2[j];
- j++;
- }
- }
- if (i < d1) {
- while (i < d1) {
- SpojenePole[i + j] = p1[i];
- i++;
- }
- }
- else {
- while (j < d2) {
- SpojenePole[i + j] = p2[j];
- j++;
- }
- }
- return SpojenePole;
- }
- int arrayLen(int p[])
- {
- return(sizeof(p)/sizeof(*p));
- }
- int main()
- {
- int *p;
- p = new int[DELKA];
- naplnPole(p, DELKA);
- vypisPole(p, DELKA);
- int *policko1,*policko2;
- policko1 = new int[DELKA/4];
- policko2 = new int[DELKA/4];
- args *arg1 = new args;
- args *arg2 = new args;
- args *arg3 = new args;
- args *arg4 = new args;
- arg1 -> pole = p;
- arg1 -> s = 0;
- arg1 -> e = DELKA/4;
- arg2 -> pole = p;
- arg2 -> s = DELKA/4;
- arg2 -> e = DELKA/2;
- arg3 -> pole = p;
- arg3 -> s = DELKA/2;
- arg3 -> e = (DELKA/4)*3;
- arg4 -> pole = p;
- arg4 -> s = (DELKA/4)*3;
- arg4 -> e = DELKA;
- //policko = setridPole(pole, DELKA, 0, DELKA/4);
- //setridPole(pole, DELKA, 0, DELKA/4);
- //vypisPole( setridPole(arg1->pole, DELKA, arg1->s, arg1->e), DELKA/4);
- //vypisPole( setridPole(arg2->pole, DELKA, arg2->s, arg2->e), DELKA/4);
- policko1 = setridPole(arg1->pole, DELKA, arg1->s, arg1->e);
- policko2 = setridPole(arg2->pole, DELKA, arg2->s, arg2->e);
- vypisPole( setridPole(arg3->pole, DELKA, arg3->s, arg3->e), DELKA/4);
- vypisPole( setridPole(arg4->pole, DELKA, arg4->s, arg4->e), DELKA/4);
- vypisPole( policko1, DELKA/4);
- vypisPole( SpojPole(policko1, policko2), DELKA/2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement