-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.CPP
50 lines (50 loc) · 855 Bytes
/
1.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
//Sorting integer and float array using single function by using templates
#include<conio.h>
#include<iostream.h>
template<class T>
void getarray(T z)
{ int n;
int i;
T a[100];
cout<<"enter number of elements in array";
cin>>n;
cout<<"\n enter elements of array";
for(i=0;i<n;i++)
cin>>a[i];
min(a,n);
}
template<class X>
void swap(X &a,X &b)
{
X temp=b;
b=a;
a=temp;
}
template<class U>
void min(U a[],int n)
{ int i;
for( i=0;i<n-1;i++)
{
for(int j=n-1;i<j;j--)
{
if(a[j]<a[j-1])
{swap(a[j],a[j-1]);}
}
}
cout<<"\nsorted array is";
for(i=0;i<n;i++)
{cout<<a[i]<<"\n";}
}
void main()
{ clrscr();
int p;
cout<<"\nenter 1 for integer array\nenter 2 for float array\n";
cin>>p;
if(p==1)
{getarray(p);}
else
if(p==2)
{float q=1.7;
getarray(q);}
getch();
}