Found 26504 Articles for Server Side Programming

Output Iterators in C++ programming

Ayush Gupta
Updated on 14-Apr-2020 12:09:22

150 Views

In this tutorial, we will be discussing a program to understand output iterators in C++.Output iterators are a part of the major five iterators. They function opposite of the input iterators in a way that they can be assigned values but can’t be accessed to fetch values.Example Live Demo#include #include using namespace std; int main(){    vectorv1 = {1, 2, 3, 4, 5};    //declaring iterator    vector::iterator i1;    for (i1=v1.begin();i1!=v1.end();++i1){       *i1 = 1;    }    return 0; }OutputNo output, because we cannot access values of output operators

Ordered Set and GNU C++ PBDS

Ayush Gupta
Updated on 14-Apr-2020 12:07:48

2K+ 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 Live Demo#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

Order of Constructor/ Destructor Call in C++

Ayush Gupta
Updated on 14-Apr-2020 12:04:57

536 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 Live Demo#include using namespace std; //parent class class Parent{    public:    Parent(){       cout

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

Ayush Gupta
Updated on 14-Apr-2020 12:02:26

601 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 Live Demo#include #include using namespace std; template ostream& operator

Merge operations using STL in C++ | merge(), includes(), set_union(), set_intersection(), set_difference(), inplace_merge

Ayush Gupta
Updated on 14-Apr-2020 11:58:44

152 Views

In this tutorial, we will be discussing a program to understand the various merge operations using STL in C++.The merge() function is used to merge two sorted containers in a way that the new container is also sorted. Further includes() is used to check if the elements from first container are present in the second one.Example Live Demo#include #include #include using namespace std; int main(){    vector v1 = {1, 3, 4, 5, 20, 30};    vector v2 = {1, 5, 6, 7, 25, 30};    //initializing resultant vector    vector v3(12);    merge(v1.begin(), v1.end(), v2.begin(),    v2.end(), v3.begin());    cout

Remove Zero Sum Consecutive Nodes from Linked List in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:51:36

2K+ Views

Suppose we have given the head of a linked list; we have to repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. So after doing so, we have to return the head of the final linked list. So if the list is like [1, 2, -3, 3, 1], then the result will be [3, 1].To solve this, we will follow these steps −Create a node called dummy, and store 0 into it, set next of dummy := headcreate one map m, store dummy for the key 0 into m, set sum = 0while ... Read More

Swap For Longest Repeated Character Substring in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:46:05

563 Views

Suppose we have a string text, so we are allowed to swap two of the characters in the string. We have to find the length of the longest substring with repeated characters. So if the input is like “ababa”, then the result will be 3, as if we swap first b with last a, or the last b with first a, then the longest repeated character will be “aaa”, so the length is 3.To solve this, we will follow these steps −Define a map cnt, set ret := 1, j := 0, n := size of text, v := 0, ... Read More

Longest Common Subsequence in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:41:22

460 Views

Suppose we have two strings text1 and text2, we have to return the length of their longest common subsequence. The ubsequence of a string is a new string generated from the original string with some characters deleted without changing the relative order of the remaining characters. (So for example "abe" is a subsequence of "abcde" but "adc" is not). A common subsequence of two strings is a subsequence that is common to both strings. So If there is no common subsequence, return 0. If the input is like “abcde”, and “ace”, then the result will be 3.To solve this, we ... Read More

Maximum of Absolute Value Expression in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:36:17

777 Views

Suppose we have two arrays of integers with equal lengths, we have to find the maximum value of: |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|. Where the maximum value is taken over all 0

Brace Expansion in C++

Arnab Chakraborty
Updated on 30-Apr-2020 15:32:58

362 Views

Suppose we have a string S that represents a list of words. Here each letter in the word has 1 or more options. If there is only one option, the letter is represented as is. If there is more than one option, then curly braces delimit the options. So for example, "{a, b, c}" will represent the options ["a", "b", "c"]. Now for example, if the input is like "{a, b, c}d{e, f}" this will represent the list ["ade", "adf", "bde", "bdf", "cde", "cdf"].Return all words that can be formed in this manner, in lexicographical order.To solve this, we will ... Read More

Advertisements