/*
	© MATTO MATTI 2018
	http://mattomatti.com/pl/fs21
	napisane przy użyciu Visual Studio Community 2015
	2018-03-01 v 1.0
*/

#include <chrono>
#include <iostream>
#include <thread>
#include <vector>

using namespace std;

void sortuj(unsigned int* dane, int n, int t) {
	std::vector<std::thread> threads;
	int pos = 0;
	for (int i = 0; i < n; ++i) {
		threads.emplace_back([dane, i, t, &pos]() {
			int w = dane[i];
			this_thread::sleep_for(chrono::seconds(w*t));
			dane[pos++] = w;
		});
	}
	for (auto& thread : threads)
		thread.join();
}

int main() {
	unsigned int n, t;
	cout << "Podaj ile jest elementow\n n = ";
	cin >> n;
	unsigned int* tab = new unsigned int[n];
	cout << "Podaj elementy:\n";
	for (int i = 0; i < n; i++)
		cin >> tab[i];
	cout << "Roznica czasu pomiedzy pobudkami (s)\n t = ";
	cin >> t;
	sortuj(tab, n, t);
	cout << "Po posortowaniu:\n";
	for (int i = 0; i < n; i++)
		cout << tab[i] << " ";
	system("pause");
	return 0;
}