JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

Iterator Type in c++ language , Input Iterator , Output , Forward , Bidirectional , Random Access Iterator

इससे पहले के article मे , Iterator को discuss किया था अब इस article मे , Iterator के type को discuss करेगे |
Iterator Categories
किसी Iterator के type निन्म है : –
Input Iterator
Output Iterator
Forward Iterator
Bidirectional Iterator
Random Access Iterator
Input Iterator:
इस input Iterator एक Iterator है जिसका use किसी container के element को access करने के लिए किया जाता है |लेकिन इनकी value को modify नहीं किया जा सकता है |
input Iterator पर निन्म operation को फॉलो किया जाता है :-
Operator (++) : इस operation मे , iterator को एक से increament किया जाता है | अतः iterator किसी data type के next data को point करता है |
Operator (==) and Operator (!=) : इस operator का use ये check करने के लिए किया जाता है की दो iterator एक ही position को point करते है या नहीं |
Operator (=) : इस operation का use किसी iterator मे value को assign करने के लिए किया जाता है |
Output Iterator:
output Iterator का use किसी container की value को modify करने के लिए किया जाता है | लेकिने in value को कभी कभी भी access या read नहीं कियता जा सकता है | इसलिए Output Iterator का use केवल write-only iterator होता है |
Output Iterator पर निन्म operation को फॉलो किया जाता है :-
Operator (++) : इस operation मे , iterator को एक से increament किया जाता है | अतः iterator किसी data type के next data को point करता है |
Operator (=) : इस operation का use किसी iterator मे value को assign करने के लिए किया जाता है |
Forward Iterator:
इस Iterator का use किसी container की value को read और write करने के लिय किया जाता है | इससे multi pass Iterator कहते है |
Forward Iterator पर निन्म operation को फॉलो किया जाता है :-
Operator (++) : इस operation मे , iterator को एक से increament किया जाता है | अतः iterator किसी data type के next data को point करता है |
Operator (==) and Operator (!=) : इस operator का use ये check करने के लिए किया जाता है की दो iterator एक ही position को point करते है या नहीं |
Operator (=) : इस operation का use किसी iterator मे value को assign करने के लिए किया जाता है |
Bidirectional iterator:
इस iterator मे Forward Iterator की सभीcapability को add किया गया है  इसके अलावा इस  Iterator मे एक और capability decrement को add किया गया है  decrement operator(–): इसका use किसी container मे value को backward डायरेक्शन मे access करने के लिए किया जाता है |
Bidirectional Iterator पर निन्म operation को फॉलो किया जाता है :-
Operator (++) : इस operation मे , iterator को एक से increament किया जाता है | अतः iterator किसी data type के next data को point करता है |
Operator (==) and Operator (!=) : इस operator का use ये check करने के लिए किया जाता है की दो iterator एक ही position को point करते है या नहीं |
Operator (=) : इस operation का use किसी iterator मे value को assign करने के लिए किया जाता है |
Decrement operator(–) : इस operation मे , iterator को एक से decreament किया जाता है | अतः iterator किसी data type के पिछला data को point करता है |
Random Access Iterator:
A Random Access iterator एक iterator है जिसका use किसी container के value को random access करने केलिए किया जाता है |इसमें Bidirectional iterator के सभी गुण को add किया गया है इसके अलावा इसमें pointer addition and pointer subtraction को add किया जग्य है जिसका use किसी container के data को random access के लिए use किया जाता है |
#include <iostream>
#include<vector>
#include<iterator>
using namespace std;
int main()
{
vector<int> v{1,2,3,4,5};
vector<int>::iterator i;
for(int i=0;i<5;i++)           // Traversal without using an iterator.
{
cout<<v[i]<<” “;
}
cout<<‘\n’;
for(i=v.begin();i!=v.end();i++)  // Traversal by using an iterator.
{
cout<<*i<<” “;
}
v.push_back(10);
cout<<‘\n’;
for(int i=0;i<6;i++)
{
cout<<v[i]<<” “;
}
cout<<‘\n’;
for(i=v.begin();i!=v.end();i++)
{
cout<<*i<<” “;
}
return 0;
}
जब इस code को execute किया जाता है तब इसका आउटपुट निन्म होगा :-
Output:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5 10
1 2 3 4 5 10
इस code मे , vector के सभी element को जब iterator के बिना  traverse किया जाता है तब हमे ये ट्रैक करना पड़ता है की container मे कितनी value को add किया गया है | लेकिन iterator के साथ एस नहीं करना होता है |
Code Reusability:
जब हम किसी iterator को use करते है तब code को reuse किया जा सकता है |  upper वाले code मे vector को लिस्ट से replace कर देते है | तब operator [] से किसी लिस्ट के element को random access नहीं किया जा सकता है | लेकिन जब हम iterator को use करते है तब इस लिस्ट के element को access किया जा सकता है |
Dynamic Processing:
c++ iterator का use किसी लिस्ट मे data value को add और डिलीट करने की facility भी होती है इससे Dynamic Processing कहते है |
code :
#include <iostream>
#include<vector>
#include<iterator>
using namespace std;
void  main()
{
vector<int> b{1,2,3,4,5};  // vector declaration
vector<int>::iterator j;
b.insert(b.begin()+1,10);
for(j=b.begin();j=b.end();j++)
{
cout<<*j<<” “;
}
getch();
}
Output:
1 10 2 3 4 5
इस article मे iterator के type को discuss किया है अब आगे के article मे c++ language के advance concept को discuss किया गया है |
Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

13 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

13 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

2 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

2 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now