#include<iostream.h>
#include<conio.h>
class bub
{
private:
int a[20],i,j,t,n;
public:
void getdata();
void putdata();
};
void bub::getdata()
{
cout<<"\nenter the size of an array:";
cin>>n;
cout<<"\nenter the array elements:";
for(i=0;i<n;i++)
cin>>a[i];
}
void bub::putdata()
{
// cout<<"\nenter the array elements:";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]<a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
cout<<"\nthe resultant bubble sort is:";
for(i=0;i<n;i++)
cout<<"\t"<<a[i];
}
void main()
{
clrscr();
bub b;
b.getdata();
b.putdata();
getch();
}
Sunday, 7 December 2014
C++ program for bubble sort
Posted by Madan
Posted on 14:35





