-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.cpp
More file actions
76 lines (52 loc) · 1007 Bytes
/
sort.cpp
File metadata and controls
76 lines (52 loc) · 1007 Bytes
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
#include<iostream>
using namespace std;
template <typename T>
T apnasort(T a[],int n)
{
int i,j;
T temp;
cout<<"before Sorting array is : ";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
// here sorting logic start n
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]<a[j])
{
temp = a[i];
a[i]=a[j];
a[j] = temp;
}
}
}
cout<<"After sorting array is : ";
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
}
int main()
{
int arr[]={5,3,4,2,1};
char str[]={'s','h','u'};
float flo[]={ 1.2, 4.4, 3.3, 5.5};
int n = sizeof(arr)/sizeof(arr[0]);
int k = sizeof(str)/sizeof(str[0]);
int l = sizeof(flo)/sizeof(flo[0]);
cout<<" we are sorting integer array here we go : "<<endl;
apnasort(arr,n);
cout<<endl;
cout<<"we are sotrting charactor array here we go "<<endl;
apnasort(str,k);
cout<<endl;
cout<<"we are sorting float array here we go : "<<endl;
apnasort(flo,l);
cout<<endl;
return 0;
}