目录

operator!=

描述 (Description)

C ++函数std::queue::operator!=测试两个队列是否相等。 通过将相应的运算符应用于基础容器来完成比较。

声明 (Declaration)

以下是std :: queue :: operator!= function form std :: queue header的声明。

C++98

template <class T, class Container>
bool operator!= (const queue<T,Container>& q1, const queue<T,Container>& q2);

参数 (Parameters)

  • q1 - 第一个队列对象。

  • q2 - 第二个队列对象。

返回值

如果两个队列不相同则返回true,否则返回false。

异常 (Exceptions)

该成员函数从不抛出异常。

时间复杂

线性即O(n)

例子 (Example)

以下示例显示了std :: queue :: operator!= function的用法。

#include <iostream>
#include <queue>
using namespace std;
int main(void) {
   queue<int> q1, q2;
   for (int i = 0; i < 5; ++i) {
      q1.push(i + 1);
      q2.push(i + 1);
   }
   q1.pop();
   if (q1 != q2)
      cout << "q1 and q2 are not identical." << endl;
   q2.pop();
   if (!(q1 != q2))
      cout << "q1 and q2 are identical." << endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

q1 and q2 are not identical.
q1 and q2 are identical.
↑回到顶部↑
WIKI教程 @2018