Sunday, 7 December 2014

C++ program for bubble sort

#include<ionstream.h>
class bubl
{
 private:
  int n,a[100],t,i,j;
 public:
  void getdata();
  void putdata();
};
void bubl::getdata()
{
 cout<<"\nenter size of array:";
 cin>>n;
 cout<<"\nenter elememnts:";
 for(i=0;i<=n;i++)
 {
  cin>>a[i];
 }
}
void bubl::putdata()
{
 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 result bubble sort is:";
 for(i=0;i<=n;i++)
 cout<<"\t"<<a[i];
}
void main()
{
 clrscr();
 bubl b;
 b.getdata();
 b.putdata();
 getch();
}