Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- void nullmatrix(int** matrix, int n) {
- int counter = n / 2 + 1;
- for (int i = 0; i < counter; i++) {
- matrix[0][i] = 0;
- matrix[1][i] = 0;
- }
- }
- int findnull(int** matrix, int n, int condition) {
- for (int i = 0; i < n; i++) {
- switch (condition) {
- case 1:
- if (matrix[0][i] == 0)
- return i;
- break;
- case 2:
- if (matrix[1][i] == 0)
- return i;
- break;
- }
- }
- }
- int findmax(int size1, int size2) {
- if (size1 > size2)
- return size1;
- else
- return size2;
- }
- int findnumberofcolumns(int** matrix, int n) {
- for (int i = 0; i < n; i++)
- if (matrix[0][i] == 0)
- return i;
- }
- void findrow(int* start, int* sort, int n, int* index, int* length) {
- int i = *index;
- int k = 0;
- int* sort = new int[n];
- do {
- sort[k] = start[i];
- i++;
- k++;
- } while (start[i] < start[i + 1]);
- *length = i - *index + 1;
- //*index += *length;
- }
- void fillsort1(int* f1, int n, int length, int* index, int* sort, int** matrix) {
- //*index += length;
- for (int i = *index; i < *index + length; i++)
- f1[i] = sort[i - *index];
- int posnum = findnull(matrix, n, 1);
- matrix[0][posnum] = length;
- *index += length;
- }
- void fillsort2(int* f2, int n, int length, int index, int* sort, int** matrix) {
- for (int i = index; i < index + length; i++)
- f2[i] = sort[i - index];
- int posnum = findnull(matrix, n, 2);
- matrix[1][posnum] = length;
- }
- void fillingfs(int n, int* start, int* f1, int* f2, int** matrix) {
- nullmatrix(matrix, n);
- int index = 0;
- int length = 0;
- int condition = 0;
- int* sort;
- for (int i = 0; i < n; i += length) {
- findrow(start, sort, n, &index, &length);
- if (condition % 2 == 0)
- fillsort1(f1, n, length, &index, sort, matrix);
- else
- fillsort2(f2, n, length, index, sort, matrix);
- condition++;
- }
- }
- int calculatek(int** matrix, int i, int condition) {
- int sum = 0;
- for (int counter = 0; counter < i; counter++)
- {
- switch (condition) {
- case 1:
- sum += matrix[0][counter];
- break;
- case 2:
- sum += matrix[1][counter];
- break;
- }
- }
- return sum;
- }
- int* sortedf(int* f1, int* f2, int** matrix, int n, int* index) {
- //int k1 = 0;
- //int k2 = 0;
- int* f = new int[n];
- int inc;
- int counter = findnumberofcolumns(matrix, n);
- for (int i = 0; i < counter; i++) {
- int size1 = matrix[0][i];
- int size2 = matrix[1][i];
- findmax(size1, size2);
- /*for (int j = *index; j < *index + size1 + size2; j++) { // 1 6 7 8
- [0] [1] [2] [3] [4] [5] [6] [7]
- if ((f1[j] < f2[j + size1]) && (j <= *index + size1)) // 2 3 4 9
- f[j] = f1[j];
- else {
- z = j;
- f[j] = f2[j + size1];
- f[j + size1] = f1[j];
- }
- if (j > *index + size1)
- f[j] = f2[j];
- }*/
- int j = *index;
- int* buf = new int[n];
- int j1 = j;
- int j2 = j;
- int z = j;
- do {
- if (f1[j] < f2[j + size1])
- {
- f[z] = f1[j];
- j1+-+;
- }
- else {
- f[z] = f2[j + size1];
- j2++;
- }
- z++;
- } while (j < *index + size1);
- }
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- int n;
- std::cin >> n;
- int* result = new int[n];
- int* start = new int[n];
- for (int i = 0; i < n; i++)
- std::cin >> start[i];
- int* f1 = new int[n];
- int* f2 = new int[n];
- int* sort = new int[n];
- int length;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement