Programming Articles

Page 1408 of 2547

Operator overloading in C++ to print contents of vector, map, pair ..

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 670 Views

In this tutorial, we will be discussing a program to understand operator overloading in C++ to print contents of vector, map and pair.Operator overloading is the function of operators which gives them the ability to act on User defined objects and work accordingly in a similar fashion.ExampleVector#include #include using namespace std; template ostream& operator

Read More

transform_inclusive_scan() function in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 115 Views

In this tutorial, we will be discussing a program to understand the transform_inclusive_scan() function in C++.Example#include #include using namespace std; namespace point_input_iterator {    template    OutputItrator transform_inclusive_scan(InputItrator first,       InputItrator last,       OutputItrator d_first,       BinaryOperation binary_op,       UnaryOperation unary_op){             *d_first = unary_op(*first);       first++;       d_first++;       for (auto it = first; it != last; it++) {          //calculating the prefix sum          *d_first = binary_op(unary_op(*it), *(d_first - ...

Read More

Order of Constructor/ Destructor Call in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 637 Views

In this tutorial, we will be discussing a program to understand the order of constructor/ destructor in C++.Order of constructor/destructor refers to the pattern in which the constructors of various classes are called during inheritance of classes.Example#include using namespace std; //parent class class Parent{    public:    Parent(){       cout

Read More

Remove Duplicates from Sorted Array II in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have a sorted array nums, we have to remove the duplicates in-place such that duplicates elements will appear at most twice and return the new length. To do this task we cannot take extra space. We have to solve this with O(1) amount of space. For example, if the array is like [0,0,0,1,1,1,1,2,3,3], then the output will be [0,0,1,1,2,3,3], its length is 7Let us see the steps −len := 2 and n := size of arrayif n

Read More

Ordered Set and GNU C++ PBDS

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 3K+ Views

In this tutorial, we will be discussing a program to understand ordered set and GNU C++ PBDS.Ordered set is a policy based structure other than those in the STL library. The ordered set keeps all the elements in a sorted order and doesn’t allow duplicate values.Example#include using namespace std; #include #include using namespace __gnu_pbds; #define ordered_set tree int main(){    //declaring ordered set    ordered_set o_set;    o_set.insert(5);    o_set.insert(1);    o_set.insert(2);    cout

Read More

Print Kth least significant bit of a number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 479 Views

In this problem, we are given two numbers n and k. Our task is to print the kth least significant bit of the number n.Let’s take an example to understand the problemInput: n = 12 , k = 3 Output 1 Explanation: Let’s see the binary representation of n: 12 = 1100Now, 3rd least significant bit is 1.To solve this problem we will use the binary bits of the number. And yield the kth bit of the number. For this, we will use binary shifting of the number and left-shift the number (k-1) times. Now on doing end operation of ...

Read More

Using class to implement Vector Quantities in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 248 Views

In this tutorial, we will be discussing a program to understand how to use class to implement vector quantities in C++.Vector quantities are the ones which have both magnitude and direction. Here we will be implementing them using classes and then performing basic operations on them.Example#include #include using namespace std; class Vector {    private:    int x, y, z;    //components of the Vector    public:    Vector(int x, int y, int z){       this->x = x;       this->y = y;       this->z = z;    }    Vector operator+(Vector v); ...

Read More

Remove Duplicates from Sorted List II in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 369 Views

Suppose we have a list of some elements. We have to remove all elements that have occurred more than once. So only the distinct elements will remain in the list. So if the list is like [1, 1, 1, 2, 2, 3, 5, 6, 6, 7, 8], then the output will be [3, 5, 7, 8], all other elements are present more than once.Let us see the steps −Create a dummy node with value -1, prev := NULL, dummyPtr := dummywhile head is not nullif next of head is present or the value of head is not same as the ...

Read More

partition_point in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 174 Views

In this tutorial, we will be discussing a program to understand partition_point in C++.Partition point is a method which returns an iterator pointing to the first value in a given range. The range is a partitioned one in which the predicate is not true.Example#include #include #include bool IsOdd(int i) { return (i % 2) == 1; } int main(){    std::vector data{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };    std::vector odd, even;    std::stable_partition(data.begin(), data.end(), IsOdd);    auto it = std::partition_point(data.begin(), data.end(),    IsOdd);    odd.assign(data.begin(), it);    even.assign(it, data.end());    std::cout

Read More

Primorial of a number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 559 Views

In this problem, we are given a number n. Our task is to print its primorial number.Primorial number (Pn#) is a number that is the product of first n prime numbers.Primorial number is similar to factorial of a number n. The difference is that factorial can be any number but in case of primorial number, all prime numbers are used.Let’s take an example to understand the problem, Input: N = 4 Output 210 Explanation: Primorial number, Pn# = 2 * 3 * 5 * 7 = 210To solve this problem, we have to find the first n prime numbers. Print ...

Read More
Showing 14071–14080 of 25,466 articles
Advertisements