skip to main |
skip to sidebar
# include<iostream.h>
#include<conio.h>
class name
{
int n,i,j,temp,a[100];
public:
void getdata();
void bubble();
};
void name::getdata()
{
cout<<"enter max size\n";
cin>>n;
cout<<"enter the numbers you want to sort\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}}
void name::bubble()
{
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}}}
cout<<"sorted list is\n";
for(i=0;i<n;i++)
cout<<a[i]<<"\n";
}
void main()
{
clrscr();
name ob;
ob.getdata();
ob.bubble();
getch();
}
OUTPUT:
enter max size
3e
Enter the numbers you want to sort
45
12
78
sorted list is
12
45
78
0 comments:
Post a Comment