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

Valarray Container in c++ language , what is c++ valarray efficiency in hindi

इससे पहले के आर्टिकल मे , STL (Standard Template Library) के basic को discuss किया है जिसमे तीन मुख्य component होते है :- (1) container (2) alogorithm (3)Iterators | Containers का algorithm या set of command है जिसका use किसी प्रकार के टाइप के दो या दो से अधिक objects के collection को manage करने के लिए किया जाता है | C++ STL (Standard Template Library) मे निन्म मुख्य containers होता है :- deque, list, vector, map ,valarray आदि | इस article मे valarray के basic को कुछ predefine functions को discuss करेगे |

std:: valarray class in C++

C++STL (Standard Template Library) मे array के सामान दो प्रकार के container को introduce किया गया है |

(1) Vector

vector एक container है जिसका structure array की तरह होता है | इसमें  मुख्य system oriented activity जैसे sorting , insertion , rearrangement , searching को perform किया जा सकता  है | vector को सार से बाकि के article मई discuss करेगे |

(2)Valarray

Valarray भी एक special container हैजिसका structure array की तरह  ही होता है | इसमें और vectorमे एक ही difference होता है :

valarray मे सभी mathematical operations को array पर efficiently apply किया जा सकता है | लेकिन vector मे कुछ basic operation जैसे sorting , insertion , rearrangement , searching , swaping और sizing आदि को perform किया जा सकता है |

valarray element-wise mathematical operations  और  generalized subscript operators जैसे slicing and indirect access को भी support करता है |

और vector से ज्यादा , valarray से container array पर operation को efficiently किया जाता है | और compleaity भी काफी कम होती है |

इसमें निन्म public functions होता है :-

1. apply() :-

इस function का use किसी valarray elements पर इस function मई pass किये गये manipulation को apply करता है | और इस function से new valarray with manipulated values return होता है |

2. sum() :- इस function का use , किसी valarray container के सभी element के sum को find out करने के लिए किया जाता है |

इन दोनों ही function के लिए combine उदहारण नींम है :-

// C++ Programe to demonstrate apply() and sum()

#include<iostream>

#include<valarray> // for valarray functions

using namespace std;

int main()

{

// Declareing and Initializing valarray

valarray<int> val_array = { 10, 2, 20, 1, 30 };

// Declaring new valarray

valarray<int> val_array1 ;

// Using apply() to increment all elements by 5

val_array1 = val_array.apply([](int a){return a=a+5;});

// Displaying new elements value

cout << “Manipulated Valarray : “;

for (int &a: val_array1) cout << a << ” “;

cout << endl;

// Displaying sum of both old and new valarray

cout << “The sum of old valarray : “;

cout << val_array.sum() << endl;

cout << “The sum of new valarray : “;

cout << val_array1.sum() << endl;

getch();

}

इस उदाहरन मे ,

val_array1 = val_array.apply([](int a){return a=a+5;})statement से val_array के सभी element पर a=a+5;operation को apply किया गया है | और इस ऑपरेशन के बाद val_array के सभी element को val_array1 मई असाइन कर दिया जाता है |

इसके अलावा , val_array.sum() से ,  val_array के सभी element के sum को calculate किया जाता है |

Output:

Manipulated Valarray : 15 7 25 6 35

The sum of old valarray : 63

The sum of new valarray : 88

3. min() :- इस फंक्शन का use का , किसी valarray container के सभी element मे से minimum element को find out करने के लिए किया जाता है |

4. maa() :- इस फंक्शन का use का , किसी valarray container के सभी element मे से maximum element को find out करने के लिए किया जाता है |

// C++ code to demonstrate the working of

// maa() and min()

#include<iostream>

#include<valarray> // for valarray functions

using namespace std;

int main()

{

// Initializing valarray

valarray<int> val_array = { 10, 2, 20, 1, 30 };

// Displaying Maximum element of valarray

cout << “The Maximum  element of valarray : “;

cout << val_array.maa() << endl;

// Displaying Minimum element of valarray

cout << “The Minimum element of valarray : “;

cout << val_array.min() << endl;

getch();

}

Output:

The Maximum element of valarray : 30

The Minimum element of valarray : 1

7. swap() :- इस function का use , किसी  valarray container के सभी element को दुसरे valarray container के element से swap करने के लिए किया जाता है |

// C++ code to demonstrate of swap()

#include<iostream>

#include<valarray> // for valarray functions

using namespace std;

int main()

{

valarray<int> val_array1 = {1, 2, 3, 4};

valarray<int> val_array2 = {2, 4, 6, 8};

// Displaying valarrays before swapping

cout << “The contents of val_array1 before swapping : “;

for (int &a : val_array1)

cout << a << ” “;

cout << endl;

cout << “The contents of val_array2 before swapping : “;

for (int &a : val_array2)

cout << a << ” “;

cout << endl;

// Use of swap() to swap the valarrays

val_array1.swap(val_array2);

// Displaying valarrays after swapping

cout << “The contents of val_array1 after swapping : “;

for (int &a : val_array1)

cout << a << ” “;

cout << endl;

cout << “The contents of val_array2 after swapping : “;

for (int &a : val_array2)

cout << a << ” “;

cout << endl;

}

Output:

The contents of val_array1 before swapping : 1 2 3 4

The contents of val_array2 before swapping : 2 4 6 8

The contents of val_array1 after swapping  : 2 4 6 8

The contents of val_array2 after swapping  : 1 2 3 4

Sbistudy

Recent Posts

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

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

3 days ago

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

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

4 days ago

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

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

7 days ago

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

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

7 days ago

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

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

7 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