Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void sort(int arr[], int N)
- {
- for (int i = 1; i < N; i++)
- {
- for (int j = 0; j < i; j++)
- {
- if (arr[j] > arr[i])
- swap(arr[i], arr[j]);
- }
- }
- }
- int main()
- {
- int N;
- cout << "N=" << endl;
- cin >> N;
- int* A = new int[N];
- for (int i = 0; i < N; i++)
- {
- A[i]=rand()%5;
- cout << A[i] << " ";
- }
- int* B = new int[N / 2];
- int* C = new int[N - (N / 2)];
- for (int i = 0; i < N; i++)
- {
- while (i < N / 2) {
- B[i] = A[i];
- i++;
- }
- C[i - (N / 2)] = A[i];
- }
- sort(B, N / 2);
- sort(C, N - (N / 2));
- int i = 0, j = 0;
- for (int f = 0; f < N; f++) {
- if ((i < N / 2) && (j < N - (N / 2)))
- {
- if (B[i] < C[j])
- {
- A[f] = B[i];
- i++;
- }
- else
- {
- A[f] = C[j];
- j++;
- }
- }
- else {
- if (i < N / 2) {
- A[f] = B[i];
- i++;
- }
- else {
- A[f] = C[j];
- j++;
- }
- }
- }
- cout << endl << "MASS";
- for (int i = 0; i < N; i++)
- cout << A[i] << " ";
- cout << endl << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment