generate_n() Function in C++

This C++ program demonstrates the generate_n() algorithm which saves the values generated by a function into a container. The program utilizes the generate_n() algorithm which is slightly different from generate() algorithm where it takes three parameters – pointer to the location where generated values will be saved, the number of values to be generated and … Read more

advertisement

generate() Function in C++

This C++ program demonstrates the generate() algorithm which saves the values generated by a function into a container. The program utilizes the generate() algorithm which takes three parameters – iterator to the beginning of the container, iterator to the end of the container and the generating function. Here is the source code of the C++ … Read more

advertisement

fill_n() Function in C++

This C++ program demonstrates the fill_n() algorithm. The program uses function fill_n() to fill some continous positions in a container. The function takes iterator from which the values are to be filled, the number of positions to be filled and the value to be filled. Here is the source code of the C++ program which … Read more

advertisement

fill() Function in C++

This C++ program demonstrates the fill() algorithm. The program uses function fill() to fill a container within specified iterator ranges. The function takes iterator to the beginning and end of the container and the value to be filled. Here is the source code of the C++ program which demonstrates the fill() algorithm. The C++ program … Read more

advertisement

replace_if() Function in C++

This C++ program demonstrates the replace() algorithm. The replace() function takes four arguments – iterator to the beginning of the container, iterator to the end of the container, element to be replaced, and the element to be replaced with. Here is the source code of the C++ program which demonstrates the replace() algorithm. The C++ … Read more

advertisement

replace() Function in C++

This C++ program demonstrates the replace() algorithm. The replace() function takes four arguments – iterator to the beginning of the container, iterator to the end of the container, element to be replaced, and the element to be replaced with. Here is the source code of the C++ program which demonstrates the replace() algorithm. The C++ … Read more

advertisement

transform() Function in C++

This C++ program illustrates the transform() algorithm. The program creates two vectors and transforms the third vector by inserting a value equal to an element from first vector raise to the power of element in second vector. The function power is passed as a predicate to the function transform(). Here is the source code of … Read more

advertisement

erase() Function in C++

This C++ program demonstrates erase() function on vectors. The erase function takes iterators to the portion of the container(like list, vector, etc.) to be deleted, i.e. if you pass the iterator to beginning and end of the container, the function will empty that container. Here is the source code of the C++ program demonstrates erase() … Read more

advertisement

C++ Program to Illustrate use of Helper Functions

This C++ program illustrates the use of helper functions. A helper function is not meant to be instantiated by end-users but it provides an useful functionality internally used within another class, hence the function is not one of the members of a class rather outside it. The program creates a helper function to print a … Read more

advertisement

std::greater in C++

This C++ program illustrates the use of greater predicate. The greater predicate is a binary function object which takes two parameters and returns true if first parameter is greater than the second parameter. We are using this predicate to compare the vectors lexicographically by using lexicographical_compare algorithm and passing greater as the fifth parameter. Here … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.