#include <iostream>
using namespace std;
#define siz 100000000
int a[siz];
void swap(int i, int j)
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
void bubble_sort(int a[], int n)
{
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(a[i]>a[j]) swap(i,j);
}
int main()
{
int n;
while(cin>>n)
{
for(int i=0;i<n;i++) cin>>a[i];
bubble_sort(a,n);
for(int i=0;i<n;i++) cout<<a[i]<<endl;
}
return 0;
}
Bubble Sort
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment