SORTING ARRAY USING SELECTION SORT.
#include <iostream>
#include <conio.h>
using namespace std;
class Array
{
private:
int *Arr, Size, Num;
public:
Array(int Siz)
{
Arr = new int[Siz];
for (int I = 0; I <Siz; I++)
{
Arr[I] = 0;
}
Num = 0;
Size = Siz;
}
void Input()
{
int No;
cout << "\nEnter Size Of Array: ";
cin >> No;
Num = No;
cout << "Enter Elements Of Array: " << endl;
for (int I = 0; I <Num; I++)
{
cin >> Arr[I];
}
}
void Select_Sort()
{
for (int I = 0; I <Num - 1; I++)
{
int Min = I;
for (int J = I + 1; J <Num; J++)
{
if (Arr[J] <Arr[Min])
{
Min = J;
int Temp = Arr[I];
Arr[I] = Arr[Min];
Arr[Min] = Temp;
}
}
}
}
void Print()
{
cout << "\nElements Of Array is: " << endl;
for (int I = 0; I <Num; I++)
{
cout << Arr[I] << endl;
}
}
~Array()
{
cout << "\n\n\n\n************PROGRAM ENDED***************";
}
};
int main()
{
Array Obj(10);
Obj.Input();
Obj.B_Sort();
Obj.Print();
getch();
return 0;
}
0 comments:
Post a Comment