Algorithms sort, find, reverse c++ In Hindi
C++ प्रोग्रामिंग लैंग्वेज में बिल्ट-इन स्टैंडर्ड टेम्पलेट लाइब्रेरी (STL) कलेक्शन C++ यूजर को मल्टीप्ल एल्गोरिदम का एक रिच सेट ग्रुप कलेक्शन प्रोवाइड करता है। ये बिल्ट-इन सपोर्टेड एल्गोरिदम कंटेनर डाटा टाइप जैसे वेक्टर, लिस्ट, सेट, आदि और अन्य इटरेटर मेथड पर मल्टीप्ल सेपरेट सिस्टम टास्क या ऑपरेशन को अप्लाई करने के लिए डिज़ाइन किए गए हैं। C++ में मौजूदा STL एल्गोरिदम इटरेटर डाटा टाइप के साथ वर्क करते हैं, जिससे ये अलग-अलग यूसेज और पर्पस के लिए कंटेनर डाटा टाइप में वर्सेटाइल हो जाते हैं। C++ प्रोग्रामिंग में मुख्य रूप से तीन और ज्यादातर यूज़ होने वाले एल्गोरिदम कांसेप्ट हैं. जो की सॉर्ट, फाइंड और रिवर्स एल्गोरिदम के रूप में है।

C++ में सॉर्ट, फाइंड और रिवर्स एल्गोरिदम <algorithm> हेडर फाइल का बिल्ट-इन फीचर्स या एलिमेंट हैं. जो C++ प्रोग्रामिंग में एल्गोरिदम के लिए एक बेसिक सपोर्टेड हेडर फाइल या डायरेक्टरी की तरह यूज़ होती है।
Sort Algorithm Concept in C++.
C++ प्रोग्रामिंग में सॉर्ट एल्गोरिदम का यूज़ कंटेनर डाटा टाइप एलिमेंट जैसे वेक्टर, ऐरे, आदि के स्टोर डाटा एलिमेंट को एक स्पेशल यूनिक ऑर्डर सीक्वेंस में अरेंज करने में किया जाता है. सामान्य रूप से आप इसे इंक्रीसिंग या डीक्रीसिंग ऑर्डर सीक्वेंस में अरेंज कर सकते है।
Syntax of the Sort Algorithm.
#include <algorithm>
sort(begin_iterator, end_iterator);
Sort Algorithm Parameters.
- begin_iterator – यह मौजूदा कंटेनर डाटा टाइप एलिमेंट रेंज के पहले एलिमेंट की ओर पॉइंट करने वाला एक इटरेटर मेथड है।
- end_iterator – यह मौजूदा कंटेनर डाटा टाइप एलिमेंट रेंज के लास्ट एलिमेंट के एक बाद पॉइंट करने वाला एक इटरेटर मेथड है।
Behavior of the Default Sorting Algorithm.
C++ प्रोग्रामिंग में डिफ़ॉल्ट रूप से, आप sort < ऑपरेटर का यूज़ करके कंटेनर डाटा टाइप एलिमेंट्स को असेंडिंग आर्डर में अरेंज या सेट कर सकते है।
Custom Sorting Methods.
इसमें C++ यूजर कंटेनर डाटा टाइप सॉर्टिंग ऑर्डर सीक्वेंस को मॉडिफाई करने के लिए एक कस्टम कम्पेरिजन फ़ंक्शन या लैम्ब्डा एक्सप्रेशन का यूज़ कर सकते हैं।
Example of the Sorting Algorithm’s usage.
#include <iostream>
#include <vector>
#include <algorithm> // here we use algorithm header file For std::sort method
using namespace std;
int main() {
vector<int> vctr = {9, 13, 17, 5, 20, 30, 22};
// here it sorting container data in ascending order default behaviour method
sort(vctr.begin(), vctr.end());
cout << “Container data Sorted in ascending sequence – “;
for (int data : vctr) {
cout << data << ” “;
}
cout << endl;
// here it sorting container data element in descending order using a custom comparator lambda method
sort(vctr.begin(), vctr.end(), greater<int>());
cout << “Container data Sorted in descending sequence – “;
for (int data : vctr) {
cout << data << ” “;
}
cout << endl;
return 0;
}
Explanation of the Sorting Algorithm’s usage.
- यहाँ इस एक्साम्प्ल में सॉर्ट एल्गोरिदम, greater<int>() कम्पेरिजन फंक्शन का यूज़ करके वेक्टर vctr डाटा एलिमेंट को पहले असेंडिंग आर्डर में और उसके बाद डीसेन्डिंग आर्डर में अरेंज कर सॉर्ट करता है।
Find Algorithm Concept in C++.
C++ प्रोग्रामिंग में find एल्गोरिदम का यूज़ कंटेनर डाटा टाइप में किसी एलिमेंट स्पेसिफिक न्यूमेरिक वैल्यू को फाइंड या सर्च करने में किया जाता है। यह C++ यूजर द्वारा दिए गए इन्टिजर वैल्यू से मैच करने वाले कंटेनर डाटा एलिमेंट के पहले आने पर एक इटरेटर वैल्यू को रिटर्न करता है।
Syntax of the Find Algorithm.
#include <algorithm>
auto it = find(begin_iterator, end_iterator, value);
Parameters of the Find Algorithm.
- begin_iterator – यह फाइंड डाटा एलिमेंट रेंज के पहले वैल्यू एलिमेंट के लिए एक इटरेटर मेथड है।
- end_iterator – यह फाइंड डाटा एलिमेंट रेंज के लास्ट एलिमेंट के बाद एक इटरेटर मेथड है।
- value – यह फाइंड एल्गोरिदम में वह वैल्यू है, जिसे आप कंटेनर वेक्टर डाटा टाइप में फाइंड करना चाहते है।
Find Algorithm return value.
यदि आपको मौजूदा कंटेनर डाटा टाइप में फाइंड एलिमेंट मिल जाता है, तो यह उस कंटेनर डाटा एलिमेंट को इंडीकेट डिस्प्ले करते हुए एक इटरेटर वैल्यू को रिटर्न करता है।
यदि मौजूदा डाटा में एलिमेंट नहीं मिलता है, तो यह end_iterator वैल्यू को रिटर्न करता है।
Example of Find Algorithm usage.
#include <iostream>
#include <vector>
#include <algorithm> // here we use algorithm header file For std::find method
using namespace std;
int main() {
vector<int> vctr = {21, 89, 64, 59, 11, 29, 01};
// here it searching for the value 67 in the vector data element
auto it = find(vctr.begin(), vctr.end(), 67);
if (it != vctr.end()) {
cout << “Search vector Element found – ” << *it << endl;
} else {
cout << “Search vector Element not found -” << endl;
}
// here it searching for a value that doesn’t exist (e.g., 11)
it = find(vctr.begin(), vctr.end(), 11);
if (it != vctr.end()) {
cout << “Search vector Element found – ” << *it << endl;
} else {
cout << “Search vector Element not found -” << endl;
}
return 0;
}
Explanation of Find Algorithm usage.
- यहाँ इस एक्साम्प्ल में find फ़ंक्शन वेक्टर में 11 न्यूमेरिक वैल्यू को फाइंड करता है। क्योंकि यह मौजूद है, इसलिए यह “Search vector Element found – 11” स्टेटमेंट को प्रिंट करता है।
- 67 वेक्टर वैल्यू को सर्च करते समय, जो वेक्टर कंटेनर डाटा टाइप में मौजूद नहीं है. यह vctr.end() वैल्यू को रिटर्न करता है. इसलिए प्रोग्राम “Search vector Element not found ” स्टेटमेंट प्रिंट करता है।
Reverse Algorithm Concept in C++.
C++ प्रोग्रामिंग में रिवर्स एल्गोरिदम का यूज़ कंटेनर डाटा टाइप में स्टोर डाटा एलिमेंट्स के ऑर्डर को रिवर्स अरेंज करने में किया जाता है।
Syntax of the Reverse Algorithm.
#include <algorithm>
reverse(begin_iterator, end_iterator);
Parameters of the Reverse Algorithm.
- begin_iterator – यह रिवर्स डाटा एलिमेंट रेंज के पहले एलिमेंट की ओर पॉइंट करने वाला एक इटरेटर मेथड है।
- end_iterator – यह रिवर्स डाटा एलिमेंट रेंज के लास्ट कंटेनर एलिमेंट के बाद पॉइंट करने वाला एक इटरेटर मेथड है।
Reverse Algorithm Effect.
कंटेनर डाटा टाइप एलिमेंट में यह एल्गोरिदम डाटा एलिमेंट्स को उनकी जगह पर रिवर्स करता है, इसका मतलब है कि यह डायरेक्ट कंटेनर डाटा टाइप एलिमेंट को मॉडिफ़ाई करता है।
Example of the Reverse Algorithm.
#include <iostream>
#include <vector>
#include <algorithm> // here we use algorithm header file For std::reverse method
using namespace std;
int main() {
vector<int> vctr = {8, 9, 2, 1, 7, 4, 6};
// here it reversing the vector data element container in place
reverse(vctr.begin(), vctr.end());
cout << “Reversed vector data element order is – “;
for (int data : vctr) {
cout << data << ” “;
}
cout << endl;
return 0;
}
Explanation of the Reverse Algorithm.
- यहाँ इस एक्साम्प्ल में reverse फ़ंक्शन वेक्टर vctr एलिमेंट को उसकी जगह पर ही रिवर्स कर देता है, और मौजूदा वेक्टर डाटा एलिमेंट्स का स्टोरेज डाटा एलिमेंट ऑर्डर रिवर्स आर्डर में प्रिंट होता है।

