Pagini recente » Cod sursa (job #309909) | Cod sursa (job #643725) | Cod sursa (job #2093963) | Cod sursa (job #129685) | Cod sursa (job #1623978)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("algsort.in");
ofstream fout ("algsort.out");
const int nmax = 500005;
int v[nmax];
void bubble_sort(int st, int dr)
{
int i, sortat=0;
while(!sortat)
{
sortat=1;
for(i=st; i<dr; i++)
if(v[i] > v[i+1])
{
swap(v[i], v[i+1]);
sortat=0;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
int n, i;
fin >> n;
for(i=1; i<=n; i++)
fin >> v[i];
bubble_sort(1, n);
for(i=1; i<=n; i++)
fout << v[i] << " ";
fin.close();
fout.close();
return 0;
}