Cod sursa(job #2025587)
| Utilizator | Data | 22 septembrie 2017 21:34:50 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("algsort.in");
ofstream out("algsort.out");
void InsertionSort(int *v, int n) {
for (int i = 2; i <= n; i++) {
int j = i;
int key = v[i];
while (j > 1 && v[j - 1] > key) {
v[j] = v[j - 1];
j--;
}
v[j] = key;
}
}
int main() {
int n, *p;
in >> n;
p = new int[n + 1];
for (int i = 1; i <= n; i++)
in >> p[i];
InsertionSort(p, n);
for (int i = 1; i <= n; i++)
out << p[i] << " ";
delete[] p;
in.close();
out.close();
return 0;
}
