Friday, 24 November 2017

C++ Program to Implement LexicoGraphical Compare in STL


Code:

#include     iostream
#include     algorithm
#include     cctype
#include     cstring
using namespace std;

bool mycomp (char c1, char c2)
{
    return tolower(c1) < tolower(c2);
}

int main ()
{
    int flen, blen;
    char foo[] = "Apple";
    char bar[] = "apartment";
    flen = strlen(foo);
    blen = strlen(bar);
    cout << boolalpha;
    cout << "Comparing foo and bar lexicographically (foo < bar): "<
    cout << "Using default comparison (operator <): ";
    cout << lexicographical_compare(foo, foo + flen, bar, bar + blen);
    cout <
    cout << "Using mycomp as comparison object: ";
    cout << lexicographical_compare(foo, foo + flen, bar, bar + blen, mycomp);
    cout <
    return 0;
}


Output:

Comparing foo and bar lexicographically (foo < bar): 
Using default comparison (operator <): true
Using mycomp as comparison object: false


------------------
(program exited with code: 0)
Press return to continue


More C++ Programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...