Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n;
- cout << "Enter n:";
- cin >> n;
- int* a = new int[n];
- for (int i = 0; i < n; i++)
- cin >> a[i];
- int i = 0, k, g, j = n - 1;
- while (i < j)
- {
- if (a[i] % 2 != 0 && a[j] % 2 == 0)
- {
- swap(a[i], a[j]); i++; j--;
- }
- if (a[i] % 2 == 0)
- {
- for (int ind = i + 1; ind < j; ind++)
- {
- if (a[ind] % 2 == 0)
- k = ind;
- }
- swap(a[i], a[k]);
- i++;
- }
- if (a[j] % 2 != 0)
- {
- for (int ind = j - 1; ind > i; ind--)
- {
- if (a[ind] % 2 != 0)
- g = ind;
- }
- swap(a[j], a[g]);
- j--;
- }
- }
- for (int b = 0; b < n; b++)
- cout << a[b];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement