#include<iostream>
using namespace std;
class bubblesort
{
int temp, array[],size;
public:
void sort(int array[],int size)
{
for(int i=0;i<size;i++)
{
for(int j=0;j<size-1-i;j++)
{
if(array[j]>array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
for(int j=0;j<size;j++)
{
cout<<array[j]<<" ";
}
cout<<endl;
}
};
int main()
{ bubblesort obj;
int size,array[size];
cout<<"enter array size"<<endl;
cin>>size;
cout<<" enter "<<size<<" element of array"<<endl;
for(int i=0;i<size;i++)
{
cin>>array[i];
}
obj.sort(array,size);
return 0;
}
No comments:
Post a Comment