Program to sort a given list using Bubble Sort in C++
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k,a[50],n;
cout<<"\n Enter Total no. of Element::";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\n Enter Element::";
cin>>a[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
k=a[j];
a[j]=a[j+1];
a[j+1]=k;
}
}
}
cout<<"\n\nSorted array::";
for(i<0;i<n;i++)
{
cout<<"\n"<<a[i];
}
getch();
}
OUTPUT
Enter Total No. Of Element :: 5
Enter Element:: 3
Enter Element:: 5
Enter Element:: 4
Enter Element:: 9
Enter Element:: 8
Sorted Array ::
3
4
5
8
9