Skip to content

Commit feab99c

Browse files
committed
update vector
1 parent 242b587 commit feab99c

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

template/vector/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_executable(vector1 vector1.cpp)
22
add_executable(vector2 vector2.cpp)
3-
add_executable(vector3 vector3.cpp)
3+
add_executable(vector3 vector3.cpp)
4+
add_executable(vector4 vector4.cpp)

template/vector/vector4.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// Created by zing on 6/14/2020.
3+
//
4+
5+
6+
#include <vector>
7+
#include <iostream>
8+
9+
using namespace std;
10+
11+
void printVector(vector<int> &v) {
12+
13+
for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
14+
cout << *it << " ";
15+
}
16+
cout << endl;
17+
}
18+
19+
void test01() {
20+
vector<int> v1; //无参构造
21+
for (int i = 0; i < 10; i++) {
22+
v1.push_back(i);
23+
}
24+
printVector(v1);
25+
26+
vector<int> v2(v1.begin(), v1.end());
27+
printVector(v2);
28+
29+
vector<int> v3(10, 100);
30+
printVector(v3);
31+
32+
vector<int> v4(v3);
33+
printVector(v4);
34+
}
35+
36+
int main() {
37+
test01();
38+
return 0;
39+
}

0 commit comments

Comments
 (0)