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

VECTOR CLASS FUNCTION in hindi , what is VECTOR CLASS FUNCTION in c++ language

इससे पहले के article मे , vector class के कुछ ही functions को discuss करेगे | अब इस article मे , vector class के कुछ advance function को discuss करेगे |

Capacity

इस function से किसी vector के capacity के साथ deal करता है | इसके लिए निन्म functions को use किया जाता है |

size() – इस function का use किसी vector के द्वारा hold किये गये  values के number को return करता है |

max_size() – इस function का use किसी vector के द्वारा hold की गयी  values की maximum number को return किया जाता है |

capacity() – इस function का use किसी vector के elements के द्वारा allocate storage space को return करता है | इसके लिए  number of element को single element के storage space को multiply किया जाता है

resize() – इस function का use, किसी container को resize करने के लिए किया जाता है जो की elements ‘g’ contain करता है |

empty() – इस function का use status को return करने के लिए किया जाता है जो की container की emptyness के status को check करता है |

shrink_to_fit() – इस function का use किसी container की capacity को reduce किया जाता है जो की किसी container की size को fit किया जाता है और अगर किसी container की capacity , selected size से ज्यादा होता है तब extra element कू destroy किया जाता है |

नीचे दिए गये प्रोग्राम मे , c++ प्रोग्राम मे  capacity के functions को use किया जाता है :-

// C++ program to illustrate the

// capacity function 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);

cout << “Size : ” << v1.size();

cout << “\nCapacity : ” << v1.capacity();

cout << “\nMax_Size : ” << v1.max_size();

// resizes the vector size to 4

v1.resize(4);

// prints the vector size after resize()

cout << “\nSize : ” << v1.size();

// checks if the vector is empty or not

if (v1.empty() == false)

cout << “\nVector is not empty”;

else

cout << “\nVector is empty”;

// Shrinks the vector

v1.shrink_to_fit();

cout << “\nVector elements are: “;

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

cout << *it << ” “;

getch();

}

Output:

Size : 5

Capacity : 8

Max_Size : 4611686018427387903

Size : 4

Vector is not empty

Vector elements are: 1 2 3 4

Element access:

reference operator [g] – इस function का use,किसी vector के element के address को point out करता है |

at(g) –  इस function का use,किसी vector के element के address / reference को point out करता है |

front() – इस function का use,किसी vector के first element के address / reference को point out करता है |

back() –  इस function का use,किसी vector के last element के address / reference को point out करता है |

data() – इस function का use , vector के array के डायरेक्ट pointer को return करता है | इसमें vector के data element को hold किया जाता है |

इस उदहारण मे , किसी vector के element के मेमोरी acess से संबंदित function को discuss किया है :-

// C++ program to illustrate the

// element accesser in vector

#include <bits/stdc++.h>

using namespace std;

int main()

{

vector<int> v1;

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

v1.push_back(i * 10);

cout << “\nReference operator [g] : v1[2] = ” << v1[2];

cout << “\nat : v1.at(4) = ” << v1.at(4);

cout << “\nfront() : v1.front() = ” << v1.front();

cout << “\nback() : v1.back() = ” << v1.back();

// pointer to the first element

int* pos = v1.data();

cout << “\nThe first element is ” << *pos;

return 0;

}

Output:

Reference operator [g] : v1[2] = 30

at : v1.at(4) = 50

front() : v1.front() = 10

back() : v1.back() = 100

The first element is 10

Modifiers:

इसमें vector class के Modifiers को discuss करेगे |

assign() – इस function का use किसी नए element को किसी vector के पुराने element को replace किया जाता है |

push_back() – इस function का use , किसी vector मे element को push किया जाता है pushing की direction backward होती है |

pop_back() – इस function का use , किसी vector मे element को pop / remove किया जाता है pushing की direction backward होती है |

insert() – इस function का use किसी vector मे किसी specified position से पहले data item को insert किया जाता है |

erase() – इस function का use किसी vector मे किसी specified position से data item को delete किया जाता है |

swap() –  इस function का use किसी vector मे data elements को swap करने के लिए किया जाता है | लेकिन दोनों vector की size same होनी चाहिए |

clear() – इस function का use किसी container के सभी data elements को डिलीट करने के लिए किया जाता है |

emplace() – इस function का use किसी container की size को बढाया जाता है |

// C++ program to illustrate the

// Modifiers in vector

#include <bits/stdc++.h>

#include <vector>

using namespace std;

void main()

{

// Assign vector

vector<int> v;

// fill the array with 10 five times

vec.assign(5, 10);

cout << “The vector elements are: “;

for (int i = 0; i < vec.size(); i++)

cout << vec[i] << ” “;

// inserts 15 to the last position

vec.push_back(15);

int n = vec.size();

cout << “\nThe last element is: ” << vec[n – 1];

// removes last element

vec.pop_back();

// prints the vector

cout << “\nThe vector elements are: “;

for (int i = 0; i < vec.size(); i++)

cout << vec[i] << ” “;

// inserts 5 at the beginning

vec.insert(vec.begin(), 5);

cout << “\nThe first element is: ” << vec[0];

// removes the first element

vec.erase(vec.begin());

cout << “\nThe first element is: ” << vec[0];

// inserts at the beginning

vec.emplace(vec.begin(), 5);

cout << “\nThe first element is: ” << vec[0];

// Inserts 20 at the end

vec.emplace_back(20);

n = vec.size();

cout << “\nThe last element is: ” << vec[n – 1];

// erases the vector

vec.clear();

cout << “\nVector size after erase(): ” << vec.size();

// two vector to perform swap

vector<int> v1, v2;

v1.push_back(1);

v1.push_back(2);

v2.push_back(3);

v2.push_back(4);

cout << “\n\nVector 1: “;

for (int i = 0; i < v1.size(); i++)

cout << v1[i] << ” “;

cout << “\nVector 2: “;

for (int i = 0; i < v2.size(); i++)

cout << v2[i] << ” “;

// Swaps v1 and v2

v1.swap(v2);

cout << “\nAfter Swap \nVector 1: “;

for (int i = 0; i < v1.size(); i++)

cout << v1[i] << ” “;

cout << “\nVector 2: “;

for (int i = 0; i < v2.size(); i++)

cout << v2[i] << ” “;

}

Output:

The vector elements are: 10 10 10 10 10

The last element is: 15

The vector elements are: 10 10 10 10 10

The first element is: 5

The first element is: 10

The first element is: 5

The last element is: 20

Vector size after erase(): 0

Vector 1: 1 2

Vector 2: 3 4

After Swap

Vector 1: 3 4

Vector 2: 1 2

इस उदाहरन मे vector के सभी operation को discuss किया गया है |

Sbistudy

Recent Posts

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

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

2 days ago

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

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

4 days ago

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

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

6 days ago

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

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

6 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

6 days 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