Vector container (basic) in c++ language in hindi

इससे पहले के article मे , vector array को use किया था लेकिन अब तक हमने discuss नहीं किया है | अब इस article  , vector और valarray को discuss करेगे | जो की c++ language का मुख्य concept होता है |

c++ language मे , template को discuss किया था | template किसी class और function को create करने के लिए  blueprint or formula होता है | उदाहरण के लिए , library containers जैसे  iterators and algorithms generic programming का उदहारण है जो की template concept से बनाया जाता है  |

ठीक उसी प्रकार , c++ language मे , array के लिए दो template होते है |

दोनों ही class template को  अलग अलग purpose के लिए बनाया जाता है |

Vector template class , container class और  algorithm के सिस्टम का पार्ट होता है | Vector template class , system oriented activity जैसे sorting , insertion , rearrangement , searching को support करता है | इसके अलावा , Vector template class मे किसी data को एक container से दुसरे container मे transfer भी किया जाता है | इसके अलावा manipulator को भी support करता है  | vector को declare करने के लिए निन्म syntax को फॉलो करता है :-

vector <double> v3(10) , v1(10) , v2 (10);

vector : ये vector को declare करने के लिए keyword को use करते है |

<double> : ये vector array के type को define करता है |

v3(10) , v1(10) और  v2 (10) : ये data variable को define किया जाता है | ये सभी values को होल्ड करता है |

इसके अलावा किसी vector को use करने के लिए vector को begin किया जाता है इसके लिए begin () function को use किया जाता है |

इसके लिए vector_variable name . begin() syntax है जिसमे vector_variable name : इसे vector को declartion मे declare किया जाता है  | और इसके अलावा किसी vector को use करने के बाद  vector को end किया जाता है इसके लिए  end() function को use किया जाता है |

इसके लिए vector_variable name . end() syntax है जिसमे vector_variable name : इसे vector को declartion मे declare किया जाता है  |

Also read : Standard exceptions in c++ language in hindi

किसी vector के variable मे operation को perform किया जाता है | अगर किसी  दो array के elements को add करके किसी तीसरे array मे assign किया जाता है |

इसके लिए निन्म code को use किया जाता है :-

transform(v1.begin(),v1.end(),v2.begin(),v3.begin())

इसके बाद v3 = v1 + v2 ;

इसके अलावा vector से releated कुछ function निन्म है :-

begin() – इस function का use किसी iterator को return करने के लिए किया जाता है जिसे किसी vector के first element को point किया जाता है |

end() – इस function का use किसी iterator को return करने के लिए किया जाता है जिसे किसी vector के last element को point किया जाता है |

rbegin() – इस function का use किसी reverse iterator को return करने के लिए किया जाता है जिसे किसी vector के last element को point किया जाता है | क्योकि इसमें transversing reverse order मे होता है |

rend() – इस function का use किसी reverse iterator को return करने के लिए किया जाता है जिसे किसी vector के first element को point किया जाता है | क्योकि इसमें transversing  reverse order मे होता है |

cbegin() – इस function का use किसी  constant iterator को return करने के लिए किया जाता है जिसे किसी vector के first element को point किया जाता है |

cend() –  इस function का use किसी  constant iterator को return करने के लिए किया जाता है जिसे किसी vector के  last element को point किया जाता है |

crbegin() – इस function का use किसी constant reverse iterator को return करने के लिए किया जाता है जिसे किसी vector के last element को point किया जाता है | क्योकि इसमें transversing reverse order मे होता है |

crend() –  इस function का use किसी constant reverse iterator को return करने के लिए किया जाता है जिसे किसी vector के first element को point किया जाता है | क्योकि इसमें transversing reverse order मे होता है | इस transversing मे ,vector का first element last element होगा |

नीचे दिए गये उदाहरन मे vector के उदाहरन को discuss करेगे |

// C++ program to illustrate the

for (int i = 1; i <= 5; i++)

v1.push_back(i); // इससे vector मे data variable को assign किया जाता है  //

cout << “Output of begin and end: “;

for (auto i = v1.begin(); i != v1.end(); ++i)

cout << “nOutput of cbegin and cend: “;

for (auto i = v1.cbegin(); i != v1.cend(); ++i)

cout << “nOutput of rbegin and rend: “;

for (auto ir = v1.rbegin(); ir != v1.rend(); ++ir)

cout << “nOutput of crbegin and crend : “;

for (auto ir = v1.crbegin(); ir != v1.crend(); ++ir)

Output of begin and end: 2 3 4 3 1

Output of cbegin and cend: 2 3 4 3 1

Output of rbegin and rend: 1 3 4 3 2

Output of crbegin and crend : 1 3 4 3 2

इस article मे vector template class के कुछ ही function को discuss किया है अब आगे के article मे , vector template class के कुछ advance function को discuss करेगे |

हम आशा करते है कि यह नोट्स आपकी स्टडी में उपयोगी साबित हुए होंगे | अगर आप लोगो को इससे रिलेटेड कोई भी किसी भी प्रकार का डॉउट हो तो कमेंट बॉक्स में कमेंट करके पूंछ सकते है |
आप इन्हे अपने Classmates & Friends के साथ शेयर कर सकते है |

Leave a Comment

Your email address will not be published. Required fields are marked *