Cod sursa(job #2122709)

Utilizator epermesterNagy Edward epermester Data 5 februarie 2018 13:46:40
Problema Sortare prin comparare Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include<fstream>
#include<climits>
using namespace std;
int main() {
	ifstream in("algsort.in");
	ofstream out("algsort.out");
	int n;
	in >> n;
	int *x = new int[n];
	for (int i = 0;i < n;++i) {
		in >> x[i];
		int j = i;
		while (j > 0 && x[j] < x[j - 1]) {
			int aux = x[j];
			x[j] = x[j - 1];
			x[j - 1] = aux;
			j--;
		}
	}
	for (int i = 0;i < n;++i)
		out << x[i] << " ";
}