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

C++ प्रोग्राम: डायरेक्ट एड्रेसिंग टेबल्स इम्प्लीमेंट करें


यह C++ प्रोग्राम डायरेक्ट एड्रेसिंग टेबल्स को इम्प्लीमेंट करता है। डायरेक्ट एड्रेसिंग टेबल्स का उपयोग तब किया जाता है जब प्रत्येक तत्व की कुंजी एक यूनिवर्सल सेट S = {0, 1, . . . ,n - 1} से ली जाती है जहां n बहुत बड़ा नहीं है और प्रत्येक कुंजी अद्वितीय है। यह तेज़ इंसर्शन, सर्चिंग और डिलीशन ऑपरेशन की सुविधा देता है।

फंक्शन और छद्मकोड

Begin    insert():       टेबल वेरिएबल्स वर्ड और की को आर्गुमेंट के रूप में लें।       T[ x.key ] = x, जहां x की का मान है।    delete():       टेबल वेरिएबल्स वर्ड और की को आर्गुमेंट के रूप में लें।       T[ x.key ] = tab(0,” ”)    search():       T[key] लौटाएं End

उदाहरण

#include<iostream> #include<cstdlib> #include<string> #include<cstdio> using namespace std; struct tab {  //टेबल के वेरिएबल्स की घोषणा।    string word;    int key;    tab()    {}    tab( int k, string w ) //वेरिएबल इनिशियलाइज़ करने के लिए कंस्ट्रक्टर। {       word=w;       key = k;    } }; void INSERT( tab T[], tab x ) {    T[ x.key ] = x; } void DELETE( tab T[], tab x ) {    T[ x.key ] = tab(0, ""); } tab SEARCH( tab T[], int key ) {    return T[ key ]; } int main() {    int i, k, c;    string str;    tab T[65536]; //टेबल का आकार इनिशियलाइज़ करें।    tab x;    for(i = 0; i < 65536;i++)       T[i] = tab(0,"");    while (1) {       cout<<"1.Insert element into the key"<<endl;       cout<<"2.Delete element from the table"<<endl;       cout<<"3.Search element into the table"<<endl;       cout<<"4.Exit"<<endl;       cout<<"Enter your Choice: ";       cin>>c;       switch(c) {          case 1: {             string str1 = "";             cout<<"Enter the key value: ";             cin>>k;             cout<<"Enter the string to be inserted: ";             cin.ignore();             getline(cin, str);             INSERT(T, tab(k, str));             break;          }          case 2:             cout<<"Enter the key of element to be deleted: ";             cin>>k;             x = SEARCH(T, k);             DELETE(T, x);             break;          case 3:             cout<<"Enter the key of element to be searched: ";             cin>>k;             x = SEARCH(T, k);             if (x.key == 0) {                cout<<"No element inserted at the key"<<endl;                continue;             }             cout<<"Element at key "<<k<<" is-> ";             cout<<"\""<<x.word<<"\""<<endl;             break;          case 4:             exit(1);          default:             cout<<"Wrong Choice"<<endl;       }    }    return 0; }

आउटपुट

1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 1 Enter the key value: 1 Enter the string to be inserted: hi 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 1 Enter the key value: 2 Enter the string to be inserted: tutorials 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 1 Enter the key value: 3 Enter the string to be inserted: point 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 3 Enter the key of element to be searched: 1 Element at key 1 is-> "hi" 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 3 Enter the key of element to be searched: 4 No element inserted at the key 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 2 Enter the key of element to be deleted: 1 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 3 Enter the key of element to be searched: 1 No element inserted at the key 1.Insert element into the key 2.Delete element from the table 3.Search element into the table 4.Exit Enter your Choice: 4

  1. - C++ में ट्राई (Trie) डेटा स्ट्रक्चर का कार्यान्वयन

    यहां हम C++ प्रोग्राम के बारे में चर्चा करेंगे जो ट्राई (Trie) को कार्यान्वित करता है। यह एक ट्री-आधारित डेटा स्ट्रक्चर है, जिसका उपयोग स्ट्रिंग्स के बड़े डेटा-सेट में कुंजी की कुशल पुनर्प्राप्ति के लिए किया जाता है। फंक्शन्स और स्यूडोकोड function insert(): यदि कुंजी मौजूद नहीं है, तो कुंजी को

  1. - C++ में अफाइन सिफर (Affine Cipher) का कार्यान्वयन

    अफाइन सिफर में, वर्णमाला के प्रत्येक अक्षर को उसके न्यूमेरिक समकक्ष में मैप किया जाता है, यह एक प्रकार का मोनोअल्फाबेटिक सब्स्टीट्यूशन सिफर है। एन्क्रिप्शन एक सरल गणितीय फंक्शन का उपयोग करके किया जाता है और वापस अक्षर में बदला जाता है। आकार m की वर्णमाला के अक्षरों को पहले 0 ... m-1 रेंज में इंटीज

  1. C++ में सीजर सिफर (Caesar Cipher) का कार्यान्वयन C++ में सीजर सिफर (Caesar Cipher) का कार्यान्वयन

    यह एक मोनो-अल्फाबेटिक सिफर है जिसमें प्लेनटेक्स्ट के प्रत्येक अक्षर को दूसरे अक्षर द्वारा प्रतिस्थापित किया जाता है ताकि सिफरटेक्स्ट बन सके। यह सब्स्टीट्यूशन सिफर योजना का सबसे सरल रूप है। इस क्रिप्टोसिस्टम को आमतौर पर शिफ्ट सिफर के रूप में संदर्भित किया जाता है। अवधारणा प्रत्येक अल्फाबेट को दूसरे