共用方式為


<queue> 運算子

operator!=

測試運算子左邊的佇列物件是否不等於右邊的佇列物件。

bool operator!=(const queue <Type, Container>& left, const queue <Type, Container>& right);

參數

left
queue 類型的物件。

right
queue 類型的物件。

傳回值

true 如果佇列不相等則為 ; false 如果佇列相等,則為 。

備註

佇列物件之間的比較是以其項目的成對比較為基礎。 如果有相同數目的項目,且個別項目擁有相同的值,則兩個佇列相等。 反之則為不相等。

範例

// queue_op_ne.cpp
// compile with: /EHsc
#include <queue>
#include <list>
#include <iostream>

int main( )
{
   using namespace std;

   // Declares queues with list base containers
   queue <int, list<int> > q1, q2, q3;

   // The following line would have caused an error because vector
   // does not support pop_front( ) and so cannot be adapted
   // by queue as a base container
   // queue <int, vector<int> > q1, q2, q3;

   q1.push( 1 );
   q2.push( 1 );
   q2.push( 2 );
   q3.push( 1 );

   if ( q1 != q2 )
      cout << "The queues q1 and q2 are not equal." << endl;
   else
      cout << "The queues q1 and q2 are equal." << endl;

   if ( q1 != q3 )
      cout << "The queues q1 and q3 are not equal." << endl;
   else
      cout << "The queues q1 and q3 are equal." << endl;
}
The queues q1 and q2 are not equal.
The queues q1 and q3 are equal.

operator<

測試運算子左邊的佇列物件是否小於右邊的佇列物件。

bool operator<(const queue <Type, Container>& left, const queue <Type, Container>& right);

參數

left
queue 類型的物件。

right
queue 類型的物件。

傳回值

true 如果運算子左邊的佇列小於且不等於運算子右邊的佇列,則為 ;否則 false為 。

備註

佇列物件之間的比較是以其項目的成對比較為基礎。 兩個佇列物件之間的小於關聯性是根據第一對不相等項目的比較。

範例

// queue_op_lt.cpp
// compile with: /EHsc
#include <queue>
#include <iostream>

int main( )
{
   using namespace std;

   // Declares queues with default deque base container
   queue <int> q1, q2, q3;

   q1.push( 1 );
   q1.push( 2 );
   q2.push( 5 );
   q2.push( 10 );
   q3.push( 1 );
   q3.push( 2 );

   if ( q1 < q2 )
      cout << "The queue q1 is less than the queue q2." << endl;
   else
      cout << "The queue q1 is not less than the queue q2." << endl;

   if ( q1 < q3 )
      cout << "The queue q1 is less than the queue q3." << endl;
   else
      cout << "The queue q1 is not less than the queue q3." << endl;
}
The queue q1 is less than the queue q2.
The queue q1 is not less than the queue q3.

operator<=

測試運算子左邊的佇列物件是否小於或等於右邊的佇列物件。

bool operator<=(const queue <Type, Container>& left, const queue <Type, Container>& right);

參數

left
queue 類型的物件。

right
queue 類型的物件。

傳回值

true 如果運算子左邊的佇列嚴格小於運算子右邊的佇列,則為 ;否則 false為 。

備註

佇列物件之間的比較是以其項目的成對比較為基礎。 兩個佇列物件之間的小於或等於關聯性,是根據第一對不相等項目的比較。

範例

// queue_op_le.cpp
// compile with: /EHsc
#include <queue>
#include <iostream>

int main( )
{
   using namespace std;
   queue <int> q1, q2, q3;

   q1.push( 5 );
   q1.push( 10 );
   q2.push( 1 );
   q2.push( 2 );
   q3.push( 5 );
   q3.push( 10 );

   if ( q1 <= q2 )
      cout << "The queue q1 is less than or equal to "
           << "the queue q2." << endl;
   else
      cout << "The queue q1 is greater than "
           << "the queue q2." << endl;

   if ( q1 <= q3 )
      cout << "The queue q1 is less than or equal to "
           << "the queue q3." << endl;
   else
      cout << "The queue q1 is greater than "
           << "the queue q3." << endl;
}
The queue q1 is greater than the queue q2.
The queue q1 is less than or equal to the queue q3.

operator==

測試運算子左邊的佇列物件是否等於右邊的佇列物件。

bool operator==(const queue <Type, Container>& left, const queue <Type, Container>& right);

參數

left
queue 類型的物件。

right
queue 類型的物件。

傳回值

true 如果佇列不相等則為 ; false 如果佇列相等,則為 。

備註

佇列物件之間的比較是以其項目的成對比較為基礎。 如果有相同數目的項目,且個別項目擁有相同的值,則兩個佇列相等。 反之則為不相等。

範例

// queue_op_eq.cpp
// compile with: /EHsc
#include <queue>
#include <list>
#include <iostream>

int main( )
{
   using namespace std;

   // Declares queues with list base containers
   queue <int, list<int> > q1, q2, q3;

   // The following line would have caused an error because vector
   // does not support pop_front( ) and so cannot be adapted
   // by queue as a base container
   // queue <int, vector<int> > q1, q2, q3;

   q1.push( 1 );
   q2.push( 2 );
   q3.push( 1 );

   if ( q1 != q2 )
      cout << "The queues q1 and q2 are not equal." << endl;
   else
      cout << "The queues q1 and q2 are equal." << endl;

   if ( q1 != q3 )
      cout << "The queues q1 and q3 are not equal." << endl;
   else
      cout << "The queues q1 and q3 are equal." << endl;
}
The queues q1 and q2 are not equal.
The queues q1 and q3 are equal.

operator>

測試運算子左邊的佇列物件是否大於右邊的佇列物件。

bool operator>(const queue <Type, Container>& left, const queue <Type, Container>& right);

參數

left
queue 類型的物件。

right
queue 類型的物件。

傳回值

true 如果運算子左邊的佇列嚴格小於運算子右邊的佇列,則為 ;否則 false為 。

備註

佇列物件之間的比較是以其項目的成對比較為基礎。 兩個佇列物件之間的大於關聯性是根據第一對不相等項目的比較。

範例

// queue_op_gt.cpp
// compile with: /EHsc
#include <queue>
#include <iostream>

int main( )
{
   using namespace std;
   queue <int> q1, q2, q3;

   q1.push( 1 );
   q1.push( 2 );
   q1.push( 3 );
   q2.push( 5 );
   q2.push( 10 );
   q3.push( 1 );
   q3.push( 2 );

   if ( q1 > q2 )
      cout << "The queue q1 is greater than "
           << "the queue q2." << endl;
   else
      cout << "The queue q1 is not greater than "
           << "the queue q2." << endl;

   if ( q1> q3 )
      cout << "The queue q1 is greater than "
           << "the queue q3." << endl;
   else
      cout << "The queue q1 is not greater than "
           << "the queue q3." << endl;
}
The queue q1 is not greater than the queue q2.
The queue q1 is greater than the queue q3.

operator>=

測試運算子左邊的佇列物件是否大於或等於右邊的佇列物件。

bool operator>=(const queue <Type, Container>& left, const queue <Type, Container>& right);

參數

left
queue 類型的物件。

right
queue 類型的物件。

傳回值

true 如果運算子左邊的佇列嚴格小於運算子右邊的佇列,則為 ;否則 false為 。

備註

佇列物件之間的比較是以其項目的成對比較為基礎。 如果有相同數目的項目,且個別項目擁有相同的值,則兩個佇列相等。 反之則為不相等。

範例

// queue_op_ge.cpp
// compile with: /EHsc
#include <queue>
#include <iostream>

int main( )
{
   using namespace std;
   queue <int> q1, q2, q3;

   q1.push( 1 );
   q1.push( 2 );
   q2.push( 5 );
   q2.push( 10 );
   q3.push( 1 );
   q3.push( 2 );

   if ( q1 >= q2 )
      cout << "The queue q1 is greater than or equal to "
           << "the queue q2." << endl;
   else
      cout << "The queue q1 is less than "
           << "the queue q2." << endl;

   if ( q1>= q3 )
      cout << "The queue q1 is greater than or equal to "
           << "the queue q3." << endl;
   else
      cout << "The queue q1 is less than "
           << "the queue q3." << endl;
}
The queue q1 is less than the queue q2.
The queue q1 is greater than or equal to the queue q3.