Cod sursa(job #2081889)
| Utilizator | Data | 5 decembrie 2017 12:28:46 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream in ("algsort.in");
ofstream out ("algsort.out");
const int M = 500000;
int v[M], n;
int main()
{
in >> n;
for(int i = 1; i <= n; i++)
in >> v[i];
int i = 1;
while(i <= n)
{
int j = i;
while(j > 0 && v[j-1] > v[j])
{
swap(v[j],v[j-1]);
j--;
}
i++;
}
for(int i = 1; i <= n; i++)
out << v[i] << " ";
return 0;
}
