Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0bba538

Browse files
Upload note code of chapter4 sequence container
1 parent 5e74915 commit 0bba538

37 files changed

+5637
-0
lines changed

‎4_STL_sequence_container/4_2_2_stl_vector.h‎

Lines changed: 890 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// filename: 4vector-test.cpp
2+
3+
#include <vector>
4+
#include <iostream>
5+
#include <algorithm>
6+
7+
using namespace std;
8+
9+
inline void printInfo(vector<int> iv) {
10+
cout << "size=" << iv.size() << " capacity=" << iv.capacity() << endl;
11+
12+
}
13+
14+
void printVector(vector<int> iv) {
15+
for (int i = 0; i < iv.size(); i++) {
16+
cout << iv[i] << " ";
17+
}
18+
cout << endl;
19+
}
20+
21+
int main() {
22+
int i;
23+
vector<int> iv(2, 9);
24+
printInfo(iv);
25+
26+
for (int i = 1; i < 5; i++) {
27+
iv.push_back(i);
28+
printInfo(iv);
29+
}
30+
31+
printVector(iv);
32+
33+
iv.push_back(i);
34+
printInfo(iv);
35+
printVector(iv);
36+
37+
iv.pop_back();
38+
iv.pop_back();
39+
printInfo(iv);
40+
41+
iv.pop_back();
42+
printInfo(iv);
43+
44+
vector<int>::iterator ivite = find(iv.begin(), iv.end(), 1);
45+
if (ivite!=iv.end())
46+
iv.erase(ivite);
47+
printInfo(iv);
48+
printVector(iv);
49+
50+
ivite = find(iv.begin(), iv.end(), 2);
51+
if (ivite!=iv.end())
52+
iv.insert(ivite, 3, 7);
53+
printInfo(iv);
54+
printVector(iv);
55+
56+
iv.clear();
57+
printInfo(iv);
58+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /