Cod sursa(job #721861)

Utilizator DaniLLeu Daniel DaniL Data 24 martie 2012 12:19:36
Problema Sortare prin comparare Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include<fstream>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");

int n , a[500001] , i , j,b,ok;
int main()
{
	f>>n;
	for(i=1;i<=n;i++)
		f>>a[i];
				
	do {
		ok = 0;
		for (i=1;i<=n-1;i++)
			if(a[i]>a[i+1])
			{
				b=a[i];
				a[i]=a[i+1];
				a[i+1]=b;
				ok=1;
			}
			
	} while (ok);
	for(i=1;i<=n;i++)
		g<<a[i]<<" ";
	
	return 0;

}