queue::operator=
描述 (Description)
C ++函数std::queue::operator=通过替换旧的内容为队列分配新内容,并在必要时修改大小。
声明 (Declaration)
以下是std :: queue :: operator = function form std :: queue header的声明。
C++98
queue<T, Container>&
operator=( const queue<T,Container>& other )
参数 (Parameters)
other - 相同类型的另一个队列对象。
返回值
返回此指针。
异常 (Exceptions)
这个函数永远不会抛出异常。
时间复杂
线性即O(n)
例子 (Example)
以下示例显示了std :: queue :: operator = function的用法。
#include <iostream>
#include <queue>
#include <list>
using namespace std;
int main(void) {
auto it1 = {1, 2, 3, 4, 5};
auto it2 = {10, 20};
queue<int> q1(it1);
queue<int> q2(it2);
q2 = q1;
cout << "Contents of q1" << endl;
while (!q1.empty()) {
cout << q1.front() << endl;
q1.pop();
}
cout << endl;
cout << "Contents of q2" << endl;
while (!q2.empty()) {
cout << q2.front() << endl;
q2.pop();
}
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Contents of q1
1
2
3
4
5
Contents of q2
1
2
3
4
5