Server Side Programming Articles - Page 1935 of 2650

List assign() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:22:18

2K+ Views

Given is th e task to show the working of the assign() function in C++.The list::assign() function is a part of the C++ standard template library. It is used to assign the values to a list and also to copy values from one list to another. header file should be included to call this function.SyntaxThe syntax for assigning new values is as follows −List_Name.assign(size, value)SyntaxThe syntax for copying values from one list to another is as follows −First_List.assign(Second_List.begin(), Second_list.end())ParametersThe function takes two parameters −First is size, that represents the size of the list and the second one is value, which ... Read More

List crbegin() and crend() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:20:41

138 Views

Given is the task to show the working of list crbegin() and crend() functions in C++.The list::crbegin() and list::crend() functions are a part of the C++ standard template library. header file should be included to call these functions.list::crbegin()This function returns the constant iterator which points to the end element of the list which will be the reverse beginning of the list. It can be used for Backtracking the list but it cannot change the values in the list which means crbegin() function can be used for iteration only.SyntaxList_Name.crbegin()ParametersThe function does not accept any parameter.Return ValueThe function returns a constant reverse ... Read More

list cbegin() and cend() functions in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:19:07

145 Views

Given is the task to show the working of list::cbegin() and list::cend functions in C++.The list::cbegin() and list::cend() functions are a part of the C++ standard template library. header file should be included to call these functions.list::cbegin()This function returns the constant iterator which points to the beginning element of the list. It can be used to traverse the list but it cannot change the values in the list which means cbegin() function can be used for iteration only.SyntaxList_Name.cbegin();ParametersThe function does not accept any parameter.Return ValueThe function returns a constant iterator that point at the beginning element of the list.list::cend()This function ... Read More

list back() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:15:40

262 Views

Given is the task to show the working of list back() function in c++.The list::back() function is a part of the C++ standard template library. It is used to display the last element of any list. header file should be included before calling this function.SyntaxList_Name.back();ParametersThe function does not accept any parameter.Return ValueThe function returns the value of the last element of the list.ExampleInput: Lt.assign(3, 10) Lt.back() Output: 10Explanation − The following example shows how we can find the last value of any list by using the back() function. The list Lt is assigned three elements, each with value 10 and ... Read More

deque assign() function in C++ STL

Sunidhi Bansal
Updated on 20-Jan-2020 07:14:55

305 Views

Given the task is to show the working of deque::assign() in C++ STL.Deque is a double ended queue. In C++, deque::assign() is an inbuilt function which is used to assign the new value to the deque container. Every time this function is called it assigns a new value to the deque container by replacing the existing values and changing the size allocated accordingly.SyntaxSyntax of deque::assign() is as follows −dequename.assign( size, val)ParametersThis function includes 2 parameters −First is the size, which represents the size of the deque container and the second one is val, which is the value contained by ... Read More

strstr() function in C/C++

Sunidhi Bansal
Updated on 20-Jan-2020 07:10:22

819 Views

strstr() function is a predefined function in “string.h” header file which is used for performing string handling. This function is used to find the first occurrence of a substring let’s say str2 in the main string let’s say str1.SyntaxSyntax of strstr() is as follows −char *strstr( char *str1, char *str2);Parameters of strstr() arestr2 is the substring which we wish to search in the main string str1Return value of strstr() isThis function returns the address pointer of the first occurrence of the substring which we are searching if found in the main string, else it will return a null when the ... Read More

Find N Unique Integers Sum up to Zero in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:38:05

335 Views

Suppose we have an integer n. We have to return any array that contains n unique integers, such that they add up to 0. So if input is n = 5, then one possible output will be [-7, -1, 1, 3, 4]To solve this, we will follow these steps −take an array A as final answer, and take x := 0for i in range 0 to n – 2A[i] = (i + 1)x := x + i + 1A[n – 1] = xreturn AExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; void print_vector(vector v){    cout

Replace Elements with Greatest Element on Right Side in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:28:08

424 Views

Suppose we have an array A. We have to replace every element by the greatest element on the right side of this element. And replace the last one by -1. So if A = [5, 17, 40, 6, 3, 8, 2], then it will be [40,40,8,8,8,2,-1]To solve this, we will follow these steps −We will read the array element from right to left.take e := -1for i := n – 1 to 0temp := ee := max between e and array[i]array[i] := tempreturn arrayExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; void print_vector(vector v){    cout

Find Numbers with Even Number of Digits in Python

Arnab Chakraborty
Updated on 29-Apr-2020 08:24:34

2K+ Views

Suppose we have a list of numbers. We have to count the numbers that has even number of digit count. So if the array is like [12, 345, 2, 6, 7896], the output will be 2, as 12 and 7896 has even number of digitsTo solve this, we will follow these steps −Take the list and convert each integer into stringif the length of string is even, then increase count and finally return the count valueExampleLet us see the following implementation to get better understanding − Live Democlass Solution(object):    def findNumbers(self, nums):       str_num = map(str, nums)   ... Read More

Element Appearing More Than 25% In Sorted Array in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:21:52

288 Views

Suppose we have an array A. There are few elements. Some elements are common. We have to return an element that is appearing more than 25% spaces in the array. So if A = [1, 2, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7], Here 4 has occurred four times. This is more than 25% of 12 (size of the array)To solve this, we will follow these steps −Read elements and store their respective frequenciesIf the frequency is greater than 25% of the array size, then return the result.ExampleLet us see the following implementation to get better understanding ... Read More

Advertisements