//Write a program to sort an elements of an array through selection sort
#include
#include
class selection
{
private:
int data[25],r,i,k,loc;
public:
void getdata();
void sort();
void showdata();
};
void selection::getdata()
{
cout< cin>>r;
cout< for(i=0;i {
cin>>data[i];
}
}
void selection::sort()
{
int temp;
for(k=0;k<=r-2;k++)
{
for(int j=k+1;j<=r-1;j++)
{
if(data[k]>data[j])
{
temp=data[k];
data[k]=data[j];
data[j]=temp;
}
}
}
}
void selection::showdata()
{
cout< for(i=0;i {
cout< }
}
void main()
{
clrscr();
selection s;
s.getdata();
s.sort();
s.showdata();
getch();
}
No comments:
Post a Comment