JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

Iterators in c++ language in hindi , what is c++ iterator implementation examples source code

what is c++ iterator implementation examples source code , Iterators in c++ language in hindi :-
इससे पहले के article मे advance c++ के topics को discuss किया था अब इस article मे c++ Iterators को discuss करेगे |
c++ Iterators
c++ Iterators केवल एक pointer है जिसका use किसी container elements को access करने के लिए किया जाता है |
Iterators का use किसी एक element से दुसरे element मे traverse करने के लिए किया जाता है | इस प्रोसेस को Iterating कहते है जिसे केवल एक container मे traversing की लिए किया जाता है |
iterator का मुख्य advantage सभी container type मे interface बनाने के लिए किया जाता है |
इसके अलावा , iterator का use किसी algorithm को बनाने के लिए किया जाट है जो की किसी container के type से free होता है |
iterator generic approach को प्रोविडे किया जाता है जिसका use किसी container के element को navigate करने के लिए किया जाता है |
इसका syntax निन्म है :-
<ContainerType> :: iterator;
<ContainerType> :: const_iterator;
iterator मे निन्म operation perform हो सकता है :
Operator (*) : इस operation का use किसी element के current position को  return करने के लिए किया जाता है जो की iterator से point होता है |
#include<iostream>
#include<conio>
void main()
{
vector<int> v = { 1, 2, 3 };
for (i = v.begin(); i != v.end(); ++i)
{
cout << *i << ” “;
}
getch();
}
इस code को execute किया जाता है तब vector data type की value को display किया जाता है |
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 करने के लिए किया जाता है |
Difference b/w Iterators & Pointers
Iterators एक smart pointer होता है जिसका use किसी complex data structures को Iterate करने के लिए किया जाता है | container का खुद का Iterators होता है | अतः Iterators का अलग अलग container के लिए एक ही interface ह्योता है | अभी container के लिए member function होते है |
begin(): इस function का use container के first element को point out करने के लिए किया जाता है |
end(): इस function का use container के last element को point out करने के लिए किया जाता है |
उदाहरन  :
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// Declaring a vector
vector<int> b = { 1, 2, 3 };
// Declaring an iterator
vector<int>::iterator i;
int j;
cout << “Without iterators = “;
// Accessing the elements without using iterators
for (j = 0; j < 3; ++j)
{
cout << b[j] << ” “;
}
cout << “\nWith iterators = “;
// Accessing the elements using iterators
for (i = b.begin(); i != b.end(); ++i)
{
cout << *i << ” “;
}
// Adding one more element to vector
b.push_back(4);
cout << “\nWithout iterators = “;
// Accessing the elements without using iterators
for (j = 0; j < 4; ++j)
{
cout << b[j] << ” “;
}
cout << “\nWith iterators = “;
// Accessing the elements using iterators
for (i = b.begin(); i != b.end(); ++i)
{
cout << *i << ” “;
}
return 0;
}
इस उदाहरन मे , किसी vector data type को define किया जाता है | और इस vector data type के element को एलेग एलेग mode मे access किया गया है |
पहले code मे elements को without using iterators के access किया गया है |
दुसरे block मे , elements को using iterators के access किया गया है |
तीसरे block मे vector मे एक और element को add किया गया है |
चोथे  code मे elements को without using iterators के access किया गया है |
पांचवा block मे , elements को using iterators के access किया गया है |उदाहरन 2
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// Declaring a vector
vector<int> b = { 1, 2, 3 };
// Declaring an iterator
vector<int>::iterator i;
int j;
// Inserting element using iterators
for (i = b.begin(); i != b.end(); ++i) {
if (i == b.begin()) {
i = b.insert(i, 7);
// inserting 7 at the beginning of b
}
}
// b contains 7 1 2 3
// Deleting a element using iterators
for (i = b.begin(); i != b.end(); ++i) {
if (i == b.begin() + 1) {
i = b.erase(i);
// i now points to the element after the
// deleted element
}
}
// b contains 5 2 3
// Accessing the elements using iterators
for (i = b.begin(); i != b.end(); ++i) {
cout << *i << ” “;
}
getch();
}
इस उदाहरन मे ,
सबसे पहले vector को declare किया गया है |
उसके बाद vector data type के beginning मे assignment operation से 7 को insert कराया |
Sbistudy

Recent Posts

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

9 hours ago

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

3 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

5 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

1 week ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

1 week 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