Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- int inputNumber()
- {
- int n;
- std::cin >> n;
- return n;
- }
- int* inputArray(int* array, int number)
- {
- for (int i = 0; i < number; i++)
- {
- std::cin >> array[i];
- }
- return array;
- }
- void output(int* res, int number)
- {
- for (int i = 0; i < number; i++)
- {
- std::cout << res[i];
- }
- }
- int* splitNumber(int* array, int* index)
- {
- int number = 0;
- int i = index[0];
- int n = index[1];
- while (array[i] < array[i + 1])
- {
- i++;
- number++;
- }
- index[0] = i;
- index[1] = n;
- return index;
- }
- int* splitArray(int* array,int* index)
- {
- int* sort = new int[];
- int i, n;
- i = index[0];
- n = index[1];
- for (i; i < i+n; i++)
- sort[i] = array[i];
- return sort;
- }
- int* sort(int* sort1, int* sort2, int* res, int* index1, int* index2) {
- int j, i, no;
- if (index1[1] > index2[1])
- {
- no = index1[1];
- for (int count = )
- }
- else
- {
- no = index2[2];
- }
- for (i; i < i + index1[1] + index2[1]; i++) {
- if (sort1[i] < sort2[i])
- res[i] = sort1[i];
- else
- j = i;
- do {
- res[j] = sort2[j];
- j++;
- } while (res[j] > sort2[j]);
- }
- }
- int* sorted(int* res, int* array, int number)
- {
- int* index1 = new int[2];
- int* index2 = new int[2];
- int counter;
- do {
- index1 = splitNumber(array, index1);
- int* sort1 = splitArray(array, index1);
- index2 = splitNumber(array, index2);
- int* sort2 = splitArray(array, index2);
- res = sort(sort1, sort2, res, index1, index2);
- counter = index1[0] + index1[1] + index2[1];
- } while (counter < number);
- return res;
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- int* sort = new int[];
- int number = inputNumber();
- int* array = new int[number];
- array = inputArray(array, number);
- int* res = new int[number];
- res = sorted(res, array, number);
- output(res, number);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement