हिंदी माध्यम नोट्स
vector container (basic) in c++ language in hindi , meaning of vector container examples
इससे पहले के 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 होते है |
(1) Vector
(2) Valarray
दोनों ही class template को अलग अलग purpose के लिए बनाया जाता है |
(1) Vector
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 किया जाता है |
किसी 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 निन्म है :-
Iterators
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
// iterators in vector
#include <iostream>
#include <vector>
using namespace std;
void main()
{
vector<int> v1;
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 << *i << ” “;
cout << “\nOutput of cbegin and cend: “;
for (auto i = v1.cbegin(); i != v1.cend(); ++i)
cout << *i << ” “;
cout << “\nOutput of rbegin and rend: “;
for (auto ir = v1.rbegin(); ir != v1.rend(); ++ir)
cout << *ir << ” “;
cout << “\nOutput of crbegin and crend : “;
for (auto ir = v1.crbegin(); ir != v1.crend(); ++ir)
cout << *ir << ” “;
getch();
}
Output:
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 करेगे |
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…