JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

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

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…

1 week ago

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

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

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

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

1 week ago

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

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

1 week ago

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

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

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