BUBBLE SORTING by making class and functions



Bubble sorting  by making class and functions
Bubble sorting useful technique to sort array. Make a class and some related functions and then bubble sorting ..



#include<iostream>
using namespace std;
const int size = 10;
class array
{
private:
int a[size];
int n;
public:
array()
{
for ( int i=0; i<size; i++ )
{
a[i];
n = 0;
}
}
void read()
{
int num;
cout<<"how many values you want to insert ?? "<<endl;
cin>>num;
for ( int i = 0; i<num; i++)
{
cout<<"Enter value: "<<endl;
cin>>a[ i ];
}
n = num;

}
void display ()
{
for (int i = 0; i<n; i++ )
cout<<a[ i]<<endl;
}

void sort()
{
for(int i = 0; i<n-1; i++)
for(int j = 0; j<n-i-1;j++)
if(a[ j+1]<a[ j ] )
{
int temp = a[ j ];
a[j] = a[ j+1 ];
a[ j+1 ] = temp;
}
}
};



void main( )
{
array arr;
arr.read( );
cout<<"The entered values are: "<<endl;
arr.display( );
arr.sort( );
cout<<"arrays values after sorting"<<endl;
arr.display( );