-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplates.h
More file actions
92 lines (79 loc) · 1.51 KB
/
Templates.h
File metadata and controls
92 lines (79 loc) · 1.51 KB
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
#ifndef TEMPLATE_H
#define TEMPLATE_H
#include <iostream>
using namespace std;
template <typename T>
T max (const T& a, const T& b, const T& c);
template <typename T>
T median (const T& a, const T& b, const T& c);
template <typename T>
T sum (const T& a, const T& b, const T& c);
template <typename T>
T max (const T array[], unsigned int count);
template <typename T>
T sum (const T array[], unsigned int count);
template <typename T>
T max (const T& a, const T& b, const T& c)
{
if(a > b && a > c)
return a;
else if(b > c && b > a)
return b;
else if(c > b && c > a)
return c;
}
template <typename T>
T median (const T& a, const T& b, const T& c)
{
if(a <= b && a >= c)
return a;
else if(a <= c && a >= b)
return a;
else if(b <= a && b >= c)
return b;
else if(b <= c && b >= a)
return b;
else if(c <= a && c >= b)
return c;
else if(c <= b && c >= a)
return c;
}
template <typename T>
T sum (const T& a, const T& b, const T& c)
{
T sum_num;
sum_num = a + b + c;
}
template <typename T>
T max (const T array[], unsigned int count)
{
if(count >= 1)
{
T temp = 0;
for(int i = 0;i < count;i++)
{
if(array[i] > temp)
{
temp = array[i];
}
}
return temp;
}
else
cout << "error!" << endl;
}
template <typename T>
T sum (const T array[], unsigned int count)
{
if(count >= 1)
{
T sum = 0;
for(int i = 0; i < count; i++)
{
sum = sum + array[i];
}
}
else
cout << "error!" << endl;
}
#endif