-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLA5.cpp
104 lines (92 loc) · 1.71 KB
/
LA5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<iostream>
using namespace std;
int n;
template<class T>
class mysort
{
private :
T a[20];
public :
void read();
void display();
void sort();
};
template<class T>
void mysort <T>:: read()
{
cout<<"\n Enter the number of the elements you want to insert : "<<endl;
cin>>n;
cout<<"\n Enter the numbers : "<<endl;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
template<class T>
void mysort<T> :: display()
{
cout<<"\n The Entered numbers are: " <<endl;
for(int i=0;i<n;i++)
{
cout<<"\n"<<a[i];
}
cout<<endl;
}
template<class T>
void mysort <T>:: sort()
{
T temp;
for(int i=0;i<(n-1);i++)
{
for(int j=(i+1);j<n;j++)
{
if(a[j] < a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
for(int k=0;k<n;k++)
{
cout<<" "<<a[k];
}
cout<<endl;
}
}
int main()
{
int ch;
do
{
cout<<"\n Enter your choice " ;
cout<<"\n 1. For integer array sorting " ;
cout<<"\n 2. For float array sorting " ;
cout<<"3.Exit"<<endl;
cin>>ch;
switch(ch)
{
case 1 :
mysort <int>s1;
s1.read();
cout<<"The Elements in the UNSORTED order are as follows:"<<endl;
s1.display();
s1.sort();
cout<<"The Elements in the SORTED order are as follows:"<<endl;
s1.display();
break;
case 2 :
mysort<float>s2;
s2.read();
cout<<"The Elements in the UNSORTED order are as follows:"<<endl;
s2.display();
s2.sort();
cout<<"The Elements in the SORTED order are as follows:"<<endl;
s2.display();
break;
default :
cout<<"\n Please, Enter the valid option "<<endl;
}
}while(ch!=3);
return 0;
}