-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplates.cpp
More file actions
54 lines (48 loc) · 917 Bytes
/
Templates.cpp
File metadata and controls
54 lines (48 loc) · 917 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
#include <iostream>
using namespace std;
template <typename T>
T mymax(T x, T y)
{
return (x > y) ? x : y;
}
int main()
{
cout << mymax<int>(4, 5) << "\n";
cout << mymax<double>(8.5, 4.0) << "\n";
cout << mymax<char>('g', 's') << "\n";
}
/*
#include <iostream>
using namespace std;
template <class T>
void bubblesort(T arr[], T n)
{
int flag = true;
while (flag)
{
flag = false;
for (int i = 1; i < n; i++)
{
if (arr[i] < arr[i - 1])
{
swap(arr[i], arr[i - 1]);
flag = true;
}
}
if (flag == false)
break;
}
}
int main()
{
int a[6] = {10, 50, 2, 45, 65};
int n = sizeof(a) / sizeof(a[0]);
bubblesort<int>(a, n);
cout << "Printing values.........."
<< "\n";
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
}
*/