কম্পিউটার

STL-এ LexicoGraphical_ Compare বাস্তবায়নের জন্য C++ প্রোগ্রাম


C++ ফাংশন std::algorithm::lexicographical_compare() পরীক্ষা করে যে একটি পরিসর আভিধানিকভাবে অন্যটির চেয়ে কম কি না। অভিধানে বর্ণানুক্রমিকভাবে শব্দ সাজানোর জন্য যে ধরনের তুলনা ব্যবহার করা হয় তা হল একটি অভিধানগত তুলনা।

ঘোষণা

টেমপ্লেট

bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);

অ্যালগরিদম

Begin
   result = lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end())
   if (result == true)
      Print v1 is less than v2
   result = lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end())
   if (result == false)
      Print v1 is not less than v2
End

উদাহরণ

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(void) {
   //initialization of v1 and v2
   vector<string> v1 = {"One", "Two", "Three"};
   vector<string> v2 = {"one", "two", "three"};
   bool result;
   result = lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end());
   if (result == true)
      cout << "v1 is less than v2." << endl;
      v1[0] = "two";
      result = lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end());
   if (result == false)
      cout << "v1 is not less than v2." << endl;
   return 0;
}

আউটপুট

v1 is less than v2.
v1 is not less than v2.

  1. STL-এ সেট_ইউনিয়ন বাস্তবায়নের জন্য C++ প্রোগ্রাম

  2. STL-এ সেট_সিমেট্রিক_ডিফারেন্স বাস্তবায়নের জন্য C++ প্রোগ্রাম

  3. STL-এ Set_Intersection বাস্তবায়নের জন্য C++ প্রোগ্রাম

  4. STL-এ সেট_ডিফারেন্স বাস্তবায়নের জন্য C++ প্রোগ্রাম