-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21Generics.cpp
More file actions
41 lines (35 loc) · 775 Bytes
/
21Generics.cpp
File metadata and controls
41 lines (35 loc) · 775 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
/**
* Name: printArray
* Print each element of the generic vector on a new line. Do not return anything.
* @param A generic vector
**/
// Write your code here
template <typename T>
void printArray(vector<T> vect) {
for (auto index : vect)
cout << index << '\n';
}
int main() {
int n;
cin >> n;
vector<int> int_vector(n);
for (int i = 0; i < n; i++) {
int value;
cin >> value;
int_vector[i] = value;
}
cin >> n;
vector<string> string_vector(n);
for (int i = 0; i < n; i++) {
string value;
cin >> value;
string_vector[i] = value;
}
printArray<int>(int_vector);
printArray<string>(string_vector);
return 0;
}