The code of lines that can be mentioned below gives you the knowledge about the lexicographical_compare() function :
Code:
using std::lexicographical_compare;
int main()
{
int B1[] = {3, 1, 4, 1, 5, 9, 3};
int B2[] = {3, 1, 4, 2, 8, 5, 7};
int B3[] = {1, 2, 3, 4};
int B4[] = {1, 2, 3, 4, 5};
const int M1 = sizeof(B1) / sizeof(int);
const int M2 = sizeof(B2) / sizeof(int);
const int M3 = sizeof(B3) / sizeof(int);
const int M4 = sizeof(B4) / sizeof(int);
bool D12 = lexicographical_compare(B1, B1 + M1, B2, B2 + M2);
bool D34 = lexicographical_compare(B3, B3 + M3, B4, B4 + M4);
cout << "B1[] < B2[]: " << (D12 ? "true" : "false") << endl;
cout << "B3[] < B4[]: " << (D34 ? "true" : "false") << endl;
}
int main()
{
bool D12 = std::lexicographical_compare(B1, B1 + M1, B2, B2 + M2);
bool D34 = std::lexicographical_compare(B3, B3 + M3, B4, B4 + M4);
}
Bookmarks