C++ Week 12
C++ Week 12
Week 12
Vector
Note
• Vector: 向量
• Iterator: 疊代器
• Erase: 抹除 ; 消除
• Modify: 修改;修飾
• Container: 容器
Outline
• Vector
• Vector declaration and initialization
• Complier setting
• Vector function
• size()
• push_back()
• pop_back()
• front() and back()
• begin() and end()
• erase()
• insert()
• Iterator
• Find
• Practice
Vector
Method 1 Method 2
Vector declaration and initialization
• We can use "[ ]" to access each element in a vector, just like
an array.
Vector size
• This function can be used to fetch the first and last element
of a vector container.
• Data type vector name.front(void);
• Data type vector name.back(void);
Vector begin and end
• The iterator find (the start address of the vector to find, the end
address of the vector to find, the target element), it will return the
address of the paired element in the range to the iterator.
• The first input integer n, which means that there are several integers
to be input, then input the string of integers in sequence, Input the
integer m, which means that there are several integers in another
group to be input, and then input the string of integers in sequence.
Compare these two sets of integers, and output the non-repeated
integers in the two sets of arrays.
input:
3
345
4
1357
output:
147
Practice
input:
3
123
456
789
01
output:
213
546
879