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

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…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

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…

2 weeks ago

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…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks 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