-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvect2.cpp
More file actions
53 lines (50 loc) · 1.48 KB
/
Copy pathvect2.cpp
File metadata and controls
53 lines (50 loc) · 1.48 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
//
// Created by 赵健 on 2021/8/17.
//
#include "vect2.h"
#include "vect3.h"
void vect2::test() {
using std::cout;
using std::vector;
vector<Review> books;
Review temp;
while (FillReview(temp)) {
books.push_back(temp);
}
int num = books.size();
if (num > 0) {
cout << "Thank you. You entered the following:\n"
<< "Rating\tBook\tn";
for (int i = 0; i < num; ++i) {
ShowReview(books[i]);
}
cout << "Reprising:\n"
<< "Rating\tBook\n";
vector<Review>::iterator pr;
for (pr = books.begin(); pr != books.end(); pr++) {
ShowReview(*pr);
}
vector<Review> oldlist(books);
if (num > 3) {
// remove 2 items
books.erase(books.begin() + 1, books.begin() + 3);
cout << "After erasure:\n";
for (pr = books.begin(); pr != books.end(); pr++) {
ShowReview(*pr);
}
// insert 1 item
books.insert(books.begin(), oldlist.begin() + 1, oldlist.begin() + 2);
cout << "After insertion:\n";
for (pr = books.begin(); pr != books.end(); pr++) {
ShowReview(*pr);
}
}
books.swap(oldlist);
cout << "Swapping oldlist with books:\n";
for (pr = books.begin(); pr != books.end(); pr++) {
ShowReview(*pr);
}
} else {
cout << "Nothing entered, nothing gained.\n";
}
}