You are on page 1of 4

#include<iostream>

#include<limits>

using namespace std;

template <class T>


class sorting
{
T a[10];
int n;
public:
void get_item()
{ cout<<"Number of elements to be inserted: ";cin>>n;
for(int i=0;i<n;i++)
{
cout<<"\n a["<<i<<"] = ";
cin>>a[i];
}
}

void sel_sort()
{
T temp;

for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
void display()
{
for(int i=0;i<n;i++)
{
cout<<" "<<a[i]<<", ";
}
cout<<"\n\n";
}

};

int main()
{
sorting<int> iarr;
sorting<char>parr;
sorting<double> darr;
cout<<"\n\n Enter Elements of Integer Array\n";
iarr.get_item();
cout<<"\n\n Enter Elements of Char Array \n";
parr.get_item();
cout<<"\n\n Enter Elements of Float Array\n";
darr.get_item();
cout<<"\n\n Elements of Integer Array\n";
iarr.display();
cout<<"\n\n Elements of Char Array \n";
parr.display();
cout<<"\n\n Elements of Float Array\n";
darr.display();
iarr.sel_sort();
cout<<"\n\n After Selection Sorting\n Elememts of Integer Array\n";
iarr.display();
parr.sel_sort();
cout<<"\n\n After Selection Sorting\n Elements of Char Array \n";
parr.display();
darr.sel_sort();
cout<<"\n\n After Selection Sorting\n Elememts of Float Array\n";
darr.display();

return 0;
}
OUTPUT

Enter Elements of Integer Array


Number of elements to be inserted: 6

a[0] = 1

a[1] = 6

a[2] = 2

a[3] = 3

a[4] = 4

a[5] = 11

Enter Elements of Char Array


Number of elements to be inserted: 4

a[0] = c

a[1] = b

a[2] = d

a[3] = f

Enter Elements of Float Array


Number of elements to be inserted: 6

a[0] = 10.25

a[1] = 5.02

a[2] = 6.35

a[3] = 5.22

a[4] = 1.54

a[5] = 1.56

Elements of Integer Array


1, 6, 2, 3, 4, 11,
Elements of Char Array
c, b, d, f,

Elements of Float Array


10.25, 5.02, 6.35, 5.22, 1.54, 1.56,

After Selection Sorting


Elememts of Integer Array
1, 2, 3, 4, 6, 11,

After Selection Sorting


Elements of Char Array
b, c, d, f,

After Selection Sorting


Elememts of Float Array
1.54, 1.56, 5.02, 5.22, 6.35, 10.25,

You might also like