qfedu-cpp-level/day9/homework/h3.cpp

34 lines
863 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 【场景】双端队列操作
// 编写一个程序演示双端队列deque的以下操作 1在队列的前面插入一个元素。 2在队列的后面插入一个元素。 3从队列的前面删除一个元素。 4从队列的后面删除一个元素。
#include <iostream>
#include <deque>
using namespace std;
template <typename T>
void print(deque<T> &dq)
{
// cout << "******************" << endl;
typename deque<T>::iterator it = dq.begin();
for (; it != dq.end(); it++)
{
cout << *it << endl;
}
cout << "------------------" << endl;
}
int main()
{
deque<string> dq;
dq.push_front("push_front");
dq.push_back("push_back");
cout << "删除前: " << endl;
print(dq);
dq.pop_front();
dq.pop_back();
cout << "删除后: " << endl;
print(dq);
return 0;
}