/*
	© MATTO MATTI 2018
	http://mattomatti.com/pl/fs28
	napisane przy użyciu Visual Studio Community 2015
	2018-08-16 v 1.0
*/

#include <iostream>

using namespace std;

void sortuj(int* tab, int n) {
	int lewy = 0, prawy = n - 1;
	while (lewy < prawy) {
		while (tab[lewy] == 0 && lewy < prawy)
			lewy++;
		while (tab[prawy] == 1 && lewy < prawy)
			prawy--;
		if (lewy < prawy) {
			tab[lewy] = 0;
			tab[prawy] = 1;
			lewy++;
			prawy--;
		}
	}
}

int main() {
	int n;
	cout << "Ile elementow ma tablica?\n n = ";
	cin >> n;
	int* tab = new int[n];
	cout << "Podaj elementy tablicy:\n";
	for (int i = 0; i < n; i++)
		cin >> tab[i];
	sortuj(tab, n);
	for (int i = 0; i < n; i++)
		cout << tab[i] << " ";
	system("pause");
	return 0;
}