# Bubble Sort

/*********************************************************

-> This C++ program is to perform bubble sort.

-> This program works in microsoft vc++ 6.0 environment.

-> The numbers are sorted in increasing order.

**********************************************************/

#include<iostream.h>

class sorting
{
private:
double *array;
int n;
public:
void input();
void bubblesort();
void output();
};

void sorting::input()
{
cout<<“****************************************************\n”
<<“This program sorts numbers in increasing order”
<<“\n\t\tusing bubblesort technique\n”
<<“****************************************************\n”;

cout<<“Enter how many numbers you are going to enter for sorting ::”;
cin>>n;
array=new double[n+1];
for(int i=1;i<=n;i++)
cin>>array[i];
}

void sorting::bubblesort()
{
for(int i=1;i<=n-1;i++)
{
for(int j=1;j<=n-i;j++)
if(array[j]>=array[j+1])
array[j]+=array[j+1],
array[j+1]=array[j]-array[j+1],
array[j]=array[j]-array[j+1];
}
}

void sorting::output()
{
cout<<“Now the sorted numbers are ::\n”;
for(int i=1;i<=n;i++)
cout<<array[i]<<‘\t’;
cout<<endl;
}

int main()
{
sorting obj;
obj.input();
obj.bubblesort();
obj.output();
return 0;
}
/******************************************************************

SAMPLE OUTPUT ::

****************************************************
This program sorts numbers in increasing order
using bubblesort technique
****************************************************
Enter how many numbers you are going to enter for sorting ::7
1.7
1.6
1.5
1.4
1.3
1.2
1.1
Now the sorted numbers are ::
1.1 1.2 1.3 1.4 1.5 1.6 1.7
Press any key to continue

******************************************************************/

## 4 thoughts on “Bubble Sort”

1. gayathri says:

Hello sir,
I’m a beginer in data structure this website is really usefull to me .
Thank u!

2. veena rajeev says:

its fine, giving full progm code sir/madam
thank you for all, who ever in the background of this thank u lot

3. hhhhhhhhhhhhhiiiiiiiiiiiiii sir this website is really usefull for me so thanks…………..

4. Ashwini says:

Hiiii,
Thanks a lot.