Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C++

C++ STL में सरणी का कार्यान्वयन


सरणी पर विभिन्न ऑपरेशन्स और स्यूडोकोड्स:

Begin In main(),    While TRUE do       Prints some choices.       Take input of choice.       Start the switch case          When case is 1             Print the size of the array.             Break          When case is 2             Insert the values in array.             Break          When case is 3             Print the front element array.             Break          When case is 4             Print the back element of array.             Break          When case is 5             Print all the elements of the array.             Break          When case is 6             Exit.          When case is default             Print wrong input. End.

उदाहरण

#include <iostream> #include <array> #include <cstdlib> using namespace std; int main() {    array<int, 7> a; //सरणी घोषित करना    array<int, 7>::iterator it; //इटरेटर के रूप में सरणी घोषित करना    int c, i; //पूर्णांक वेरिएबल्स घोषित करना    a.fill(0);    int cnt = 0;    while (1) {       cout<<"1.Size of the array"<<endl;       cout<<"2.Insert Element into the Array"<<endl;       cout<<"3.Front Element of the Array"<<endl;       cout<<"4.Back Element of the Arrary"<<endl;       cout<<"5.Display elements of the Array"<<endl;       cout<<"6.Exit"<<endl;       cout<<"Enter your Choice: ";       cin>>c;       switch(c) {          case 1:             cout<<"Size of the Array: "; // सरणी का आकार प्रिंट करें।             cout<<a.size()<<endl;             break;          case 2:             cout<<"Enter value to be inserted: "; // सरणी में मान दर्ज करें।             cin>>i;             a.at(cnt) = i;             cnt++;             break;          case 3:             cout<<"Front Element of the Array: "; //सरणी का फ्रंट एलिमेंट प्रिंट करें।             cout<<a.front()<<endl;             break;          case 4:             cout<<"Back Element of the Arrary: "; //सरणी का बैक एलिमेंट प्रिंट करें।             cout<<a.back()<<endl;             break;          case 5:             for (it = a.begin(); it != a.end(); ++it ) //सरणी के सभी एलिमेंट्स प्रिंट करें।             cout <<" "<< *it;             cout<<endl;             break;          case 6:             exit(1); //बाहर निकलें             break;          default:             cout<<"Wrong Choice"<<endl;       }    }    return 0; }

आउटपुट

1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 1 Size of the Array: 7 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 2 Enter value to be inserted: 7 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 2 Enter value to be inserted: 6 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 2 Enter value to be inserted: 5 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 2 Enter value to be inserted: 4 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 2 Enter value to be inserted: 3 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 2 Enter value to be inserted: 2 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 2 Enter value to be inserted: 1 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 3 Front Element of the Array: 7 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 4 Back Element of the Stack: 1 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 5 7 6 5 4 3 2 1 1.Size of the array 2.Insert Element into the Array 3.Front Element of the Array 4.Back Element of the Array 5.Display elements of the Array 6.Exit Enter your Choice: 6 exit status 1

  1. C++ STL में Set_Symmetric_Difference का कार्यान्वयन C++ STL में Set_Symmetric_Difference का कार्यान्वयन

    यह C++ प्रोग्राम set_symmetric_difference को लागू करने के लिए है। दो सेट का सिमेट्रिक डिफरेंस उन तत्वों द्वारा बनाया जाता है जो एक सेट में मौजूद होते हैं, लेकिन दूसरे में नहीं। सामान्य सेट ऑपरेशन हैं: Set Union Set Intersection Symmetric Set Difference या Exclusive-OR Set Difference या Subtraction

  1. C++ STL में Set_Intersection का कार्यान्वयन C++ STL में Set_Intersection का कार्यान्वयन

    दो सेट का इंटरसेक्शन केवल उन तत्वों द्वारा बनता है जो दोनों सेट में कॉमन होते हैं। फंक्शन द्वारा कॉपी किए गए तत्व हमेशा पहले सेट से उसी क्रम में आते हैं। दोनों सेट में तत्व पहले से क्रमबद्ध होने चाहिए। सामान्य सेट ऑपरेशन हैं: Set Union Set Intersection Symmetric Set Difference या Exclusive-OR Set

  1. C++ STL में Set_Difference का कार्यान्वयन C++ STL में Set_Difference का कार्यान्वयन

    दो सेट का डिफरेंस केवल उन तत्वों द्वारा बनता है जो पहले सेट में मौजूद होते हैं, दूसरे सेट में नहीं। फंक्शन द्वारा कॉपी किए गए तत्व हमेशा पहले सेट से उसी क्रम में आते हैं। दोनों सेट में तत्व पहले से क्रमबद्ध होने चाहिए। सामान्य सेट ऑपरेशन हैं: Set Union Set Intersection Symmetric Set Difference या