-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path81.cpp
53 lines (49 loc) · 1.08 KB
/
81.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
//generic bubble sort
#include<iostream>
using namespace std;
template<class X>
void bubblesort(X *items,int count)
{
X t;
for(int i=1;i<count;i++)
{
for(int j=count-1;j>=i;j--)
{
if(items[j-1]>items[j])
{
//swapping the elements
t = items[j-1];
items[j-1] = items[j];
items[j]=t;
}
}
}
}
template<class X>
void print(X *items,int count)
{
for(int i=0;i<count;i++)
{
cout<<items[i]<<" ";
}
cout<<endl;
}
int main()
{
int arr1[] = {3,2,1,4,5,5,8,11,6,12,4};
double arr2[] = {1.2,5.6,2.3,7.9,3.6,7.6};
int n1 = sizeof(arr1)/sizeof(arr1[0]);
int n2 = sizeof(arr2)/sizeof(arr2[0]);
cout<<"\nUnsorted Integer values : ";
print(arr1,n1);
cout<<"Unsorted Double values : ";
print(arr2,n2);
//sorting through generic sort
bubblesort(arr1,n1);
bubblesort(arr2,n2);
cout<<"\nSorted Integer values : ";
print(arr1,n1);
cout<<"Sorted Double values : ";
print(arr2,n2);
return 0;
}