38 lines
702 B
C++
38 lines
702 B
C++
// deque 的删除操作
|
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
template <typename T>
|
|
void print(deque<T> &dq)
|
|
{
|
|
typename deque<T>::iterator it = dq.begin();
|
|
while (it != dq.end())
|
|
{
|
|
cout << *it << " ";
|
|
it++;
|
|
}
|
|
cout << endl;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
string m[] = {"a", "b", "c", "d", "e"};
|
|
deque<string> dq(m, m + 5);
|
|
print(dq);
|
|
|
|
deque<string>::iterator del_it = dq.begin() + 1;
|
|
// for (int i = 0; i < 3; i++)
|
|
// {
|
|
// // dq.erase() 会删除当前元素并返回下一个元素的迭代器
|
|
// del_it = dq.erase(del_it);
|
|
// }
|
|
|
|
// 第二种删除方式
|
|
dq.erase(del_it, del_it + 3);
|
|
|
|
print(dq);
|
|
|
|
return 0;
|
|
}
|