Tuesday, August 27, 2019

C++ Language Program for Sort in Selection Sort.


BACHELOR OF COMPUTER APPLICATION (B.C.A.) FIRST SEMESTER

Here you will get simple C++ program 
C++ Language Program for Sort in Selection Sort.
IT IS THE SMALLEST LOGIC USED FOR CODING OF THIS PROGRAM.
IN WHICH YOU CAN CREATE OWN VARIABLES AND FUNCTIONS.

User will input will be an unsorted form in Array and that array is sorted by Selection Sort,then it will be display on screen.


The program coding is given below.
#include <iostream.h>
#include <conio.h>
class Abc
{
int A[10],MIN,LOC;
public:
void getdata()
{
cout<<"Enter Elements: ";
for (int i=1;i<=5;i++)
{
cin>>A[i];
}
}
void min(int k)
{
MIN=A[k];
LOC=k;
for (int j=k+1;j<=5;j++)
{
if (MIN>A[j])
{
MIN=A[j];
LOC=j;
}
}
}
void selection()
{
int temp;
for (int k=1;k<=4;k++)
{
min(k);
temp=A[k];
A[k]=A[LOC];
A[LOC]=temp;
}
}
void display()
{
cout<<"\nSelection Sort:\n";
for (int i=1;i<=5;i++)
{
cout<<A[i]<<" ";
}
}
};
void main()
{
clrscr();
Abc a1;
a1.getdata();
a1.selection();
a1.display();
getch();
}
Output will be given after you compile it.

No comments:

Post a Comment