upper_bound() Algorithm in C++

This C++ program demonstrates last occurence of an element using upper_bound algorithm. The program takes an element from the input and the is passed to the upper_bound() function alongwith the iterators to the beginning and end of the vector. The function returns an iterator to the first occurence of the element. Here is the source … Read more

advertisement

lower_bound() Algorithm in C++

This C++ program demonstrates first occurence of an element using lower_bound algorithm. The program takes an element from the input and the is passed to the lower_bound() function alongwith the iterators to the beginning and end of the vector. The function returns an iterator to the first occurence of the element. Here is the source … Read more

advertisement

stable_partition() Algorithm in C++

This C++ program rearranges the container elements using stable_partition() algorithm. The algorithm rearranges the elements of the container such that the elements for which predicate returns true precede the elements for which the predicate returns false. The relative order of the elements is preserved. Here is the source code of the C++ program which rearranges … Read more

advertisement

partition() Algorithm in C++

This C++ program rearranges the container elements using partition() algorithm. The algorithm rearranges the elements of the container such that the elements for which predicate returns true precede the elements for which the predicate returns false. Unlike stable_partition(), the relative order of the elements is not preserved. Here is the source code of the C++ … Read more

advertisement

nth_element() Function in C++

This C++ program demonstrates the nth_element algorithm. The function rearranges the container elements in such a way that the element at the nth position is the element that would be in that position in a sorted sequence. The other elements are left without any specific order, except that none of the elements preceding nth are … Read more

advertisement

partial_sort_copy() Function in C++

This C++ program demonstrates using partial_sort_copy() algorithm. The algorithm partially sorts the container elements and copies the sorted elements into another container according to the capacity of the second container. Here is the source code of the C++ program which demonstrates using partial_sort_copy() algorithm. The C++ program is successfully compiled and run on a Linux … Read more

advertisement

stable_sort() Function in C++

This C++ program demonstrates the stable_sort() algorithm. The program creates vector of objects of class Student which has attributes – name, section and group. The stable_sort algorithm first sorts the elements with name as the key and then the elements are sorted with their section as the key. The order of the elements with same … Read more

advertisement

sort() Function in C++

This C++ program demonstrates the sort() algorithm. The program creates a vector of strings, sorts them using sort algorithm without predicate to sort them in default order and with greater predicate to sort them in reverse order and prints it. Here is the source code of the C++ program which demonstrates the sort() algorithm. The … Read more

advertisement

iter_swap() in C++

This C++ program demonstrates the iter_swap() algorithm. The creates an array and a vector of integers and swaps the elements at odd positions of vector and array. The elements of vector and array are then printed on standard output. Here is the source code of the C++ program which demonstrates the iter_swap() algorithm. The C++ … Read more

advertisement

swap_ranges() Function in C++

This C++ program demonstrates the swap_ranges() algorithm. The program creates two arrays of integers and swaps the elements by passing iterators to the range of elements to be swapped into the function swap_ranges. Here is the source code of the C++ program which demonstrates the swap_ranges() algorithm. The C++ program is successfully compiled and run … 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 & technical discussions at Telegram SanfoundryClasses.