deque - STL C++

operator<()

Declaration

bool operator<(deque<X, A>, deque<X, A>);

Description

This is the overloaded less than operator for deques.

Header Include

#include <deque>

Example

#include <iostream>
#include <deque>

int main()
{
	using namespace std;

	deque<int>* qpaD[3];

	// Create a three deque instances
	deque<int> qD1;
	qD1.push_back(4);
	qD1.push_back(5);
	qD1.push_back(1);
	qpaD[0] = &qD1;

	deque<int> qD2;
	qD2.push_back(1);
	qD2.push_back(5);
	qD2.push_back(4);
	qpaD[1] = &qD2;

	deque<int> qD3;
	qD3.push_back(1);
	qD3.push_back(5);
	qD3.push_back(4);
	qpaD[2] = &qD3;

	// Compare the deques to each other and themselves
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			deque<int>::iterator qIter;
			for (qIter = qpaD[i]->begin(); qIter != qpaD[i]->end(); ++qIter) {
				cout << *qIter << " ";
			}
			// Apply the operator to the ith and jth deques
			cout << ((*(qpaD[i]) < *(qpaD[j])) ? "<  " : ">= ");
			for (qIter = qpaD[j]->begin(); qIter != qpaD[j]->end(); ++qIter) {
				cout << *qIter << " ";
			}
			cout << endl;
		}
	}

	cin.get();
	return 0;
}

Output

operator<() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.