Skip to content

Commit ccd0b07

Browse files
committed
add data struct and algorithm in C++ version
1 parent ba38668 commit ccd0b07

File tree

1 file changed

+34
-0
lines changed
  • Data_Structures_Algorithms_And_Applications/ch01

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
template <class T>
5+
T abc(T a, T b, T c)
6+
{
7+
return a + b * c;
8+
}
9+
10+
template <class Ta, class Tb, class Tc>
11+
Ta abc(const Ta& a, const Tb& b, const Tc& c)
12+
{
13+
return a + b * c;
14+
}
15+
16+
int main()
17+
{
18+
int i = 5, j = 6, k = 0;
19+
20+
int ret = abc<int>(i, j, k);
21+
cout << ret << endl;
22+
23+
float a = 7.8, b = 1.2, c = 3.1;
24+
25+
float res = abc<float>(a, b, c);
26+
cout << res << endl;
27+
28+
float x = 3.2, ret_val = 0.0;
29+
int y = 3, z = 4;
30+
ret_val = abc<float, int, int>(x, y, z);
31+
cout << ret_val << endl;
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)